用php从数组中提取段数据
我的数据库中存在类似的数据: 我需要将图像地址数据提取到数组级别[pic]到[image]值 我想用PHP从[Image]中提取图像地址数据 我需要提取图像地址数据使用移动应用程序,数据接收移动应用程序通过JsonArray和Json_编码从php 谢谢你的帮助用php从数组中提取段数据,php,arrays,mobile,extract,Php,Arrays,Mobile,Extract,我的数据库中存在类似的数据: 我需要将图像地址数据提取到数组级别[pic]到[image]值 我想用PHP从[Image]中提取图像地址数据 我需要提取图像地址数据使用移动应用程序,数据接收移动应用程序通过JsonArray和Json_编码从php 谢谢你的帮助 Array ( [0] => Array ( [pic] => Array ( [0] => Ar
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
)
)
)
)
您可以使用此函数获取所有图像数据
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'));
您尝试过什么吗?预期输出?是的,我尝试过,但没有回答我不介意的问题,它是否会在手机上进行编码也没关系,请使用Rahul Meshram描述,非常感谢Dude@EtherNet很乐意帮忙。如果此答案或任何其他答案解决了您的问题,请将其标记为已接受。