如何做php数组遍历
遍历
$arr = array(
2=>array('dddd'),
3=>array(
array('eeee')
),·
);
foreach ($arr as $key => $value) {
if(is_array($value)){
// p($value);
foreach ($value as $k => $v) {
// p($v);
if (is_array($v)) {
foreach ($v as $ke => $val) {
p($val);
}
}
}
}
}
定义函数Q 实体 转义
函数:function Q($str){
return addslashes(htmlspecialchars($str));
}
//数组遍历
<?php
include '../function.php';
$arr = array(
'a' => 'A',
//'b' => 'B',
'c' => array(
'd' => array(
'e'=>'E'
)
),
);
foreach ($arr as $key => $value) {
// p($value);
if(is_array($value)){
foreach ($value as $k => $v) {
if(is_array($v)){
foreach ($v as $ke => $val) {
p($ke);
}
}
}
}
}
操作方法
- 01
遍历 $arr = array( 2=>array('dddd'), 3=>array( array('eeee') ),· ); foreach ($arr as $key => $value) { if(is_array($value)){ // p($value); foreach ($value as $k => $v) { // p($v); if (is_array($v)) { foreach ($v as $ke => $val) { p($val); } } } } } 定义函数Q 实体 转义 函数:function Q($str){ return addslashes(htmlspecialchars($str)); } //数组遍历 <?php include '../function.php'; $arr = array( 'a' => 'A', //'b' => 'B', 'c' => array( 'd' => array( 'e'=>'E' ) ), ); foreach ($arr as $key => $value) { // p($value); if(is_array($value)){ foreach ($value as $k => $v) { if(is_array($v)){ foreach ($v as $ke => $val) { p($ke); } } } } }