如何提交PHP数组stdClass对象 [英] How to filer PHP Array stdClass Object
本文介绍了如何提交PHP数组stdClass对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我像这样从JSON中获取数组中的数据
I have data below in the array that I got from JSON like this
$page = file_get_contents("http://giswebcenter.mwa.co.th/mwa/ashx/Proxy.ashx");
$json_output = json_decode($page);
然后当我print_r($ json_output)
and then I have data like this when I print_r($json_output)
stdClass Object
(
[success] => 1
[total] => 850
[message] =>
[data] => Array
(
[0] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 03
[BLOCK] => 04
[MATL] => ST
[LENGTH] => 516.492
)
[1] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 03
[BLOCK] => 05
[MATL] => SCP
[LENGTH] => 19.177
)
[2] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 03
[BLOCK] => 05
[MATL] => ST
[LENGTH] => 519.355
)
[3] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 03
[BLOCK] => 06
[MATL] => SCP
[LENGTH] => 59.713
)
[4] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 03
[BLOCK] => 06
[MATL] => ST
[LENGTH] => 476.866
)
[5] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 04
[BLOCK] => 03
[MATL] => SCP
[LENGTH] => 64.875
)
[6] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 04
[BLOCK] => 03
[MATL] => ST
[LENGTH] => 44.888
)
[7] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 04
[BLOCK] => 05
[MATL] => SCP
[LENGTH] => 19.979
)
[8] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 04
[BLOCK] => 05
[MATL] => ST
[LENGTH] => 28.591
)
[9] => stdClass Object
(
[BRANCH] => 01
[ZONE] => 04
[BLOCK] => 07
[MATL] => SCP
[LENGTH] => 38.967
)
)
)
我想过滤数组中的数据,因为ZONE = '03'
并且我已经尝试过使用array_filter()编写此代码,但请注意.
I'd like to filter data in the array as ZONE='03'
and I've tried this code with array_filter() but noting.
function filterZone($obj)
{
return $obj['data']->BRANCH == "01";
}
$BRANCH = array_filter($json_output, 'filterZone');
print_r($BRANCH);
任何人都可以帮忙或建议我这样做吗?
谢谢.
Can anyone help or suggest me to do this?
Thank you.
推荐答案
非常简单.您正在尝试array_filter并非真正是数组的东西(或者至少是您要迭代的数组).
Pretty straightforward. You're trying to array_filter something that isn't really an array (or at least the array you're attempting to iterate over).
您想运行更多类似的内容:
You want to run something more like this:
function filterZone($obj)
{
return $obj['ZONE'] == '03';
}
$BRANCH = array_filter($json_output->data, 'filterZone');
print_r($BRANCH);
这篇关于如何提交PHP数组stdClass对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文