根据索引搜索特定值

我有一个这样的数组


[proceedings] => Array

(

    [0] => stdClass Object

        (

            [pro_id] => 38

            [doh] => 2019-08-24

            [ndoh] => 2019-08-24

            [stage_id] => 2

            [order_sheet] => 

        )


    [1] => stdClass Object

        (

            [pro_id] => 38

            [doh] => 2019-08-24

            [ndoh] => 2019-08-28

            [stage_id] => 108

            [order_sheet] => order sheet

        )


)

我有一个喜欢它的值“2019-08-24”,我想根据[doh]我的完整数组中的键来搜索该值,我该如何尝试很多方法,但它无济于事。


我想匹配[doh]所有数组索引中的值


当年话下
浏览 166回答 2
2回答

森林海

但是你foreach()应该工作,如果你的财产将它与$doh价值进行比较,$doh='2019-08-24';$array = [&nbsp; (object)&nbsp; ['pro_id' => 38,'doh' => '2019-04-24','ndoh' => '2019-05-24','stage_id' => 2,'order_sheet' =>'oder sheet'] ,&nbsp; (object)&nbsp; ['pro_id' => 30,'doh' => '2019-08-24','ndoh' => '2019-08-24','stage_id' => 3,'order_sheet' =>'oder sheet'] ,];foreach($array as $obj) {&nbsp; &nbsp; if ($doh == $obj->doh) {&nbsp; &nbsp; &nbsp; &nbsp; $entry[] = $obj;&nbsp; &nbsp; }}print_r($entry);与array_filter(),<?php$array = [&nbsp; (object)&nbsp; ['pro_id' => 38,'doh' => '2019-04-24','ndoh' => '2019-05-24','stage_id' => 2,'order_sheet' =>'oder sheet'] ,&nbsp; (object)&nbsp; ['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);

倚天杖

或者你可以使用 array_filter()<?php$a_proceedings = Array(&nbsp; &nbsp; (object) array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pro_id' => '38',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'doh' => '2019-08-24',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'ndoh' => '2019-08-24',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'stage_id' => 2,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'order_sheet' => '',&nbsp; &nbsp; &nbsp; &nbsp; ),&nbsp; &nbsp; (object) array&nbsp; &nbsp; &nbsp; &nbsp; (&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pro_id' => 38,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'doh' => '2019-08-24',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'ndoh' => '2019-08-28',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'stage_id' => 108,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'order_sheet' => 'order sheet',&nbsp; &nbsp; &nbsp; &nbsp; ));var_dump(array_filter($a_proceedings, function($elem) {&nbsp; &nbsp; return $elem->doh == '2019-08-24';}));
打开App,查看更多内容
随时随地看视频慕课网APP