php array print key and value code example
Example 1: php foreach echo key value
foreach($page as $key => $value) {
echo "$key is at $value";
}
Example 2: how to get array key in php
<?php
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');
for($i = 0; $i< sizeof($array);$i++){
if (key($array[$i]) == 'apple') {
echo key($array).'<br />';
}
}
?>
Example 3: php take out 2 level array key value
foreach($bigArray as $array){
foreach($array as $key=>$value){
echo $key;
}
}