2013-07-24 17 views
0

創建陣列我有這樣PHP - 從數組

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_idmerge像這樣

array(45,46,...); 

有人能幫助我嗎?

回答

5

由於密鑰還包含的ID,你可以使用array_keys()

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

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

感謝您的輸入。其實你的代碼包含錯誤。 ''ids = array();'然後你在'object-> termId中錯過'$';' – Giri

+0

@Giri Meh,我很快輸入了它,最近我還沒有在做PHP。 – thatidiotguy

+0

嗯..謝謝。我已經upvoted你的答案:) – Giri