时间:2021-07-01 10:21:17 帮助过:6人阅读
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';
}
?>
http://www.bkjia.com/PHPjc/445432.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445432.htmlTechArticlephp 遍历二维数组与多维数组代码关于php的数组,我们来讲一下,二维数组与多维的遍历代码,下面举了三个实例来测试数组的遍历php代码函...