简体   繁体   中英

php - Create array from an array

I have an array like this

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)

I would like to strip only term_id from that array and merge it like this

array(45,46,...);

Can someone help me?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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