【发布时间】:2018-10-31 14:55:18
【问题描述】:
我有一个这样的 php 数组:
$arr = array(
0 => array(
"text" => "eventyrer",
"children"=> array(
4 => array(
"text" => "news",
"children"=> array(
1=> array("text"=>"a")
)
),
5 => array(
"text" => "nyheter",
"children"=> array(
1=> array("text"=>"b")
)
)
)
),
1 => array(
"text" => "eventyrer2017",
"children"=> array(
6 => array(
"text" => "news",
"children"=> array(
1=> array("text"=>"c")
)
),
8 => array(
"text" => "nyheter",
"children"=> array(
1=> array("text"=>"d")
)
)
)
)
);
我怎样才能得到这样的输出:
$array = array(
0 => "eventyrer/news/a",
1 => "eventyrer/nyheter/b",
2 => "eventyrer2017/news/c",
4 => "eventyrer2017/nyheter/d",
)
这里我需要获取“文本”,然后附加“/”,然后通过“孩子”获取他们的文本。 子文本将与父文本一起添加。
【问题讨论】:
-
会不会有多个孩子?
-
您尝试过什么吗?您是否检查过 SO 上的其他预先存在的页面?你需要无限递归还是你的输入数组的深度是已知的?
-
您能否将该数组粘贴为 JSON 编码字符串,以便我在此端解码和使用它?
-
哦,是的,对不起,我以为是 print_r 输出一分钟,抱歉,哈哈:-P
标签: php arrays multidimensional-array parent children