繁体   English   中英

php-从数组创建数组

[英]php - Create array from an array

我有这样的数组

array (size=1)
  45 => 
    object(stdClass)[37]
      public 'term_id' => string '45' (length=2)
      public 'name' => string 'Appointments' (length=12)
      public 'slug' => string 'appointments' (length=12)
      public 'term_group' => string '0' (length=1)
      public 'term_taxonomy_id' => string '48' (length=2)
      public 'taxonomy' => string 'tribe_events_cat' (length=16)
      public 'description' => string '' (length=0)
      public 'parent' => string '0' (length=1)
      public 'count' => string '1' (length=1)
      public 'object_id' => string '625' (length=3)
   46 => 
    object(stdClass)[37]
      public 'term_id' => string '46' (length=2)
      public 'name' => string 'Appointmentx' (length=12)
      public 'slug' => string 'appointmentx' (length=12)
      public 'term_group' => string '0' (length=1)
      public 'term_taxonomy_id' => string '48' (length=2)
      public 'taxonomy' => string 'tribe_events_cat' (length=16)
      public 'description' => string '' (length=0)
      public 'parent' => string '0' (length=1)
      public 'count' => string '1' (length=1)
      public 'object_id' => string '626' (length=3)

我只想从该数组中剥离term_id并像这样merge

array(45,46,...);

有人能帮我吗?

由于键还包含ID,因此可以使用array_keys()

$ids = array_keys($array);
$ids = array();

foreach($array as $object)
{
    $ids[] = $object->termId;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM