Tags
PHP , foreach
Asked 2 years ago
25 Apr 2022
Views 469
debugger

debugger posted

PHP: how foreach work ?


$array = array(1, 2, 3, 4, 5);

how to print and manipulate the array with foreach in PHP ?
eclipse-learner

eclipse-learner
answered Apr 25 '22 00:00


$array = array(1, 2, 3, 4, 5);
foreach($array as $value){
echo $value;
}

above code print all values from the array


$array = array("a"=>1, "b"=>2,"c"=>3,"d"=>4, "e"=>5);
foreach($array as $value){
echo "Key:".$value;
echo "Value:".$value;

}

above code print all keys and values from the array
Post Answer