我有一个问题,我必须做10个循环取决于数组的数字,以获得数据。
我修复了一些帮助从我的其他帖子,但我有一个问题重命名
我使用的数组
Array
(
[catalog] => Array
(
[book] => Array
(
[0] => Array
(
[took] => Array
(
[dodo] => Array
(
[ahmadz] => Array
(
[lolo] => Array
(
[tata] => Array
(
[author] => ahmadz
[title] => Midnight Rain
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.
)
)
)
)
)
)
[1] => Array
(
[took] => Array
(
[dodo] => Array
(
[ahmadz] => Array
(
[lolo] => Array
(
[tata2] => Array
(
[author] => Ralls, Kim
[title] => Midnight Rain
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.
)
)
)
)
)
)
)
)
)
我就是这样得到一个特定的数据的
$author_array = array();
array_walk_recursive($array, function($value, $key) {
if (in_array($key, array("author"))) {
echo $author_array[] = $value;
}
});
问题是在这些值
之前 [author] => ahmadz
[title] => Midnight Rain
[genre] => Fantasy
[price] => 5.95
我有不同的键
tata and tata2
我只想得到"tata" key
中的值但是上面的代码同时返回"tata"one_answers"tata2"键的值
请帮我从一个键得到数据,而不是两个
这是一个有点草率的方法,但它应该工作。只需查找tata键,然后从中提取作者字段。
$author_array = array();
array_walk_recursive($array, function($value, $key) {
if (in_array($key, array("tata"))) {
echo $author_array[] = $value["author"];
}
});
直接使用嵌套foreach循环
foreach($数组("目录")("书")作为关键=>美元值){foreach(美元价值("带")("渡渡鸟")("ahmadz")("罗罗语")作为key2 => value2美元){回声"作者:"。$ value2("作者");}}