php accessing to '' key in array code example
Example 1: 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 2: php array access by key
$newarray = array();
foreach($shop as $key=>$value) {
$newarray[$key]['Title'] = $value['Title'];
$newarray[$key]['Number'] = $value['Number'];
}
echo "<pre>";print_r($newarray);