关于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,'stripslashes');
- print_r($array);
实例三,遍历二维数组,代码如下:
- $employee[]=array("jas,join","www.Vevb.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';
- }
新闻热点
疑难解答