Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

for each array

$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++;
}
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #array
ADD COMMENT
Topic
Name
1+3 =