📜  对于每个数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:14.678000             🧑  作者: Mango

代码示例6
$array  = array("dog", "rabbit", "horse", "rat", "cat");
$x = 1;
$length = count($array);

foreach($array as $animal){
    if($x === 1){
        //first item
        echo $animal; // output: dog
    }else if($x === $length){
        echo $animal; // output: cat
    }
    $x++;
}