Home > php教程 > php手册 > body text

php 遍历二维数组与多维数组代码

WBOY
Release: 2016-06-13 11:17:49
Original
1015 people have browsed it

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';

 }

?>


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!