当前位置:编程学习 > 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.'<br/>';
  }
 }
}
 
$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","www.zzzyk.com",20);
 $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';

 }

?>

补充:Php教程,Php函数
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,