我将XML文件转换为关联数组以提取数据,问题是我必须根据数组编号制作10个循环才能获取数据。
有没有更好的方法来获取特定的列数据而不创建许多循环?因为我想把它们分配给变量。
我尝试从
获取数据的数组Array
(
[catalog] => Array
(
[comp] => Array
(
[0] => Array
(
[look] => Array
(
[shp] => Array
(
[wok] => Array
(
[group] => Array
(
[customer] => Array
(
[author] => jack
[title] => Midnight Rain1
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies.
)
[customer2] => Array
(
[author] => lemass
[title] => Midnight Rain1
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies.
)
)
)
)
)
)
[1] => Array
(
[look] => Array
(
[shp] => Array
(
[wok] => Array
(
[group] => Array
(
[customer] => Array
(
[author] => jon
[title] => Midnight Rain1
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies.
)
[customer2] => Array
(
[author] => kirito
[title] => Midnight Rain1
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies.
)
)
)
)
)
)
)
)
)
我试图获取这样的数据。
我有2个数组customer
和customer1
我想获得这样的数据
customer => author
输出
jack
jon
因为它们位于customer
数组
有可能吗?
答案 0 :(得分:1)
$comps = $arr['Shp']['test'];
foreach ($comps as $comp) {
if (is_array($comp))
echo $comp['Shp2'] ['customer'] ['address'] ['ad1']; }
or use this echo $comp['test'] ['Shp2'] ['customer'] ['address'] ['ad1'];