我有一个类似于数据库中的存在数据: 我需要将图像地址数据提取到数组级别[pic]到[image]值 我想使用PHP从[image]中提取图像地址数据 我需要提取图像地址数据以用于移动应用程序,通过php中的JsonArray和Json_encode在移动应用程序上接收数据 感谢您的帮助
Array
(
[0] => Array
(
[pic] => Array
(
[0] => Array
(
[image] => file_ext/reporter/images/IMG_20181116_210224_191.jpg
[width] => 1280
[height] => 960
)
[1] => Array
(
[image] => file_ext/reporter/images/IMG_20181116_210250_912.jpg
[width] => 1280
[height] => 960
)
[2] => Array
(
[image] => file_ext/reporter/images/IMG_20181116_210256_141.jpg
[width] => 1280
[height] => 960
)
[3] => Array
(
[image] => file_ext/reporter/images/IMG_20181116_210303_326.jpg
[width] => 1280
[height] => 960
)
[4] => Array
(
[image] => file_ext/reporter/images/IMG_20181116_210310_857.jpg
[width] => 1280
[height] => 960
)
[5] => Array
(
[image] => file_ext/reporter/images/IMG_20181116_210345_024.jpg
[width] => 1280
[height] => 960
)
)
)
)
答案 0 :(得分:0)
您可以使用此功能来获取所有图像数据,
function array_column_recursive(array $haystack, $needle) {
$found = [];
array_walk_recursive($haystack, function($value, $key) use (&$found, $needle) {
if ($key == $needle)
$found[] = $value;
});
return $found;
}
$data = json_encode(array_column_recusrive($input,'image'));