php 遍歷二維數組與多維數組代碼關於php的數組,我們來講一下,二維數組與多維的遍歷代碼,下面舉了三個實例來測試數組的遍歷php代碼函數了。
php教程 遍歷二維數組與多維數組代碼
關於php的數組,我們來講一下,二維數組與多維的遍歷代碼,下面舉了三個實例來測試數組的遍歷php代碼函數了。
*/
function arr_foreach ($arr) {
if (!is_array ($arr)) {
return false;
}
foreach ($arr as $key => $val ) {
if (is_array ($val)) {
arr_foreach ($val);
} else {
echo $val.'
';
}
}
}
$arr1 = array (1=>array(11,12,13,14=>array(141,142)),2,3,4,5);
arr_foreach ($arr1);
//php遍歷多維數組
$array = array('a'=>"'as","b"=>array('c'=>"'cc","n"=>array('1'=>"'sdf")),'f'=>array('c'=>"'sdf","g"=>array("c")));
function handleeach(&$array,$functionname)
{
foreach($array as $k=>$v)
{
if(is_array($v))
{
handleeach(&$array[$k],$functionname);
}
else
$array[$k] = $functionname($v);
}
}
handleeach($array,'strips教程lashes');
print_r($array);
//實例三,遍歷二維數組
$employee[]=array("jas,join",");
$employee[]=array("june,join","programmer",20);
$employee[]=array("aili,join","programmer",20);
$employee[]=array("doe,jane","programmer",20);$newname = array();
foreach ($employee as $record){
$newname[] = isset($record[0]) ? $record[0] : 'no name';
}
?>