2 回答
TA贡献2011条经验 获得超2个赞
但是你foreach()应该工作,如果你的财产将它与$doh价值进行比较,
$doh='2019-08-24';
$array = [
(object) ['pro_id' => 38,'doh' => '2019-04-24','ndoh' => '2019-05-24','stage_id' => 2,'order_sheet' =>'oder sheet'] ,
(object) ['pro_id' => 30,'doh' => '2019-08-24','ndoh' => '2019-08-24','stage_id' => 3,'order_sheet' =>'oder sheet'] ,
];
foreach($array as $obj) {
if ($doh == $obj->doh) {
$entry[] = $obj;
}
}
print_r($entry);
与array_filter(),
<?php
$array = [
(object) ['pro_id' => 38,'doh' => '2019-04-24','ndoh' => '2019-05-24','stage_id' => 2,'order_sheet' =>'oder sheet'] ,
(object) ['pro_id' => 30,'doh' => '2019-08-24','ndoh' => '2019-08-24','stage_id' => 3,'order_sheet' =>'oder sheet'] ,
];
$doh='2019-08-24';
$entry = array_filter($array, function($e) use($doh) { return $e->doh==$doh; });
print_r($entry);
TA贡献1828条经验 获得超3个赞
或者你可以使用 array_filter()
<?php
$a_proceedings = Array
(
(object) array(
'pro_id' => '38',
'doh' => '2019-08-24',
'ndoh' => '2019-08-24',
'stage_id' => 2,
'order_sheet' => '',
),
(object) array
(
'pro_id' => 38,
'doh' => '2019-08-24',
'ndoh' => '2019-08-28',
'stage_id' => 108,
'order_sheet' => 'order sheet',
)
);
var_dump(array_filter($a_proceedings, function($elem) {
return $elem->doh == '2019-08-24';
}));
- 2 回答
- 0 关注
- 165 浏览
添加回答
举报