【发布时间】:2019-11-08 18:03:52
【问题描述】:
我正在通过 ajax 帖子接收以下多维数组:
array(1) {
["result"] => array(3) {
[0] => array(2) {
[0] => string(1)
"0" [1] => array(2) {
["id"] => string(5)
"1§10" ["children"] => array(2) {
[0] => array(1) {
["id"] => string(6)
"1§3$0"
} [1] => array(1) {
["id"] => string(6)
"1§1$0"
}
}
}
} [1] => array(2) {
[0] => string(1)
"1" [1] => array(1) {
["id"] => string(5)
"3§20"
}
} [2] => array(2) {
[0] => string(1)
"2" [1] => array(2) {
["id"] => string(5)
"2§30" ["children"] => array(1) {
[0] => array(1) {
["id"] => string(6)
"2§2$0"
}
}
}
}
}
}
有没有办法用php只一个一个地返回字符串?数组中字符串的深度无关紧要,因为我只会解析和分解 id 字符串。
【问题讨论】:
-
试试
array_walk_recursive()了解更多信息请看php.net/manual/en/function.array-walk-recursive.php,记住这个功能有一些限制,一定要通过。 -
你也可以使用
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::LEAVES_ONLY); foreach ($it as $item) {...} -
@Stantastic 我的帖子回复你了吗?这个问题还在等待中……
标签: php arrays for-loop nested-loops