是否可以在不使用循环的情况下在php(wordpress)中找到对象数组中存在的值

时间:2018-12-27 07:23:06

标签: php wordpress loops

我加入了wp_post和wp_post_meta表并生成了这个对象数组。我可以不使用任何循环而在数组中找到field1的值吗? field1 == 1150存在 field1 == 2150不存在

array (size=4)
  0 => 
    object(stdClass)[1306]
      public 'ID' => string '415' (length=3)
      public 'post_title' => string 'hello' (length=22)
      public 'field1' => string '' (length=0)
  1 => 
    object(stdClass)[1307]
      public 'ID' => string '473' (length=3)
      public 'post_title' => string 'hai' (length=6)
      public 'field1' => string '1150' (length=0)
  2 => 
    object(stdClass)[1308]
      public 'ID' => string '1189' (length=4)
      public 'post_title' => string 'news test' (length=9)
      public 'field1' => string '1187' (length=4)
  3 => 
    object(stdClass)[1309]
      public 'ID' => string '1208' (length=4)
      public 'post_title' => string 'news test r' (length=11)
      public 'field1' => string '1189' (length=4)

1 个答案:

答案 0 :(得分:0)

因为PHP 7 array_column也适用于对象。

n-1