Php 如何从数组/对象中获取值
我调用upload函数,它返回一个变量。当我执行Php 如何从数组/对象中获取值,php,arrays,json,Php,Arrays,Json,我调用upload函数,它返回一个变量。当我执行var\u dump($x)时,它显示以下内容: {"files":[{"name":"1004046_469695273124093_104592888_n_1_28860.jpg","size":0,"type":"image\/jpeg","error":"abort","delete_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/?file=1004046_469695
var\u dump($x)
时,它显示以下内容:
{"files":[{"name":"1004046_469695273124093_104592888_n_1_28860.jpg","size":0,"type":"image\/jpeg","error":"abort","delete_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/?file=1004046_469695273124093_104592888_n_1_28860.jpg","delete_type":"DELETE"}]}array(1) {
["files"]=>
array(1) {
[0]=> object(stdClass)#24 (6) {
["name"]=> string(47) "1004046_469695273124093_104592888_n_1_28860.jpg"
["size"]=> int(0)
["type"]=> string(10) "image/jpeg"
["error"]=> string(5) "abort"
["delete_url"]=> string(104) "http://www.xxx.com/upload/uploader/server/php/?file=1004046_469695273124093_104592888_n_1_28860.jpg"
["delete_type"]=> string(6) "DELETE"
}
}
}
我尝试了var\u dump(json\u decode($x))
,结果为空
我的问题是如何从中获取值名称
尝试了以下两种方法:
echo $x->files[0]->name;
echo " ********************** ";
echo $x['files'][0]->name;
echo " ********************** ";
结果是
{"files":[{"name":"1004046_469695273124093_104592888_n_1_14299.jpg","size":78289,"type":"image\/jpeg","url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/files\/1004046_469695273124093_104592888_n_1_14299.jpg","thumbnail_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/files\/thumbnail\/1004046_469695273124093_104592888_n_1_14299.jpg","delete_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/?file=1004046_469695273124093_104592888_n_1_14299.jpg","delete_type":"DELETE"}]}{"files":[{"name":"1004046_469695273124093_104592888_n_1_12920.jpg","size":0,"type":"image\/jpeg","error":"abort","delete_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/?file=1004046_469695273124093_104592888_n_1_12920.jpg","delete_type":"DELETE"}]}
**********************
{"files":[{"name":"1004046_469695273124093_104592888_n_1_15697.jpg","size":0,"type":"image\/jpeg","error":"abort","delete_url":"http:\/\/www.xxx.com\/upload\/uploader\/server\/php\/?file=1004046_469695273124093_104592888_n_1_15697.jpg","delete_type":"DELETE"}]}1004046_469695273124093_104592888_n_1_15697.jpg
**********************
您是否尝试过:
$name_val = $x->files[0]->name;
您是否尝试过:
$name_val = $x->files[0]->name;
我想可能是$x[“文件”][0]->名称。。。顶层元素似乎是一个数组,它首先生成$x?你能提供更多的上下文吗?在第一个数组之前有一个字符串。我做了json_解码,将其拆分为},然后我将右侧视为一个数组“$x['files'][0]->name”给了我结果,我认为它可能是$x[“files”][0]->name。。。顶层元素似乎是一个数组,它首先生成$x?你能提供更多的上下文吗?在第一个数组之前有一个字符串。我做了json_解码,将其拆分为},然后我将右侧作为数组“$x['files'][0]->name给了我结果