我如何过滤stdClass的对象 [英] How can I filter stdClass object
本文介绍了我如何过滤stdClass的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面我有数据把JSON到数组
I have data below from putting JSON to Arrays
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
) ....
我要在阵列ZONE =03来过滤数据。
结果谁能给的例子code做到这一点?
结果三江源。
I want to filter data in Array as ZONE = '03'.
Can anyone give the example code to do this?
Thankyou.
推荐答案
您可以利用array_filter的 http://php.net/manual/en/function.array-filter.php
You could make use of array_filter http://php.net/manual/en/function.array-filter.php
$input = (object)array(
'success'=>1,
'total'=>850,
'data'=>array(
(object)array('ZONE'=>'01'),
(object)array('ZONE'=>'04'),
(object)array('ZONE'=>'04'),
(object)array('ZONE'=>'04'),
(object)array('ZONE'=>'03'),
(object)array('ZONE'=>'02')
)
);
$output = array_filter($input->data,function($object){
return ($object->ZONE == '04');
});
print_r($output);
array_filter由数组中的测试每个项目,并返回TRUE或FALSE的作品,在返回的括号标记是一个快捷方式返回一个布尔值。
array_filter works by testing each item in the array and returning TRUE or FALSE, the bracket notation on the return is a shortcut to returning a boolean value.
这篇关于我如何过滤stdClass的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文