1

My array return this:

Array ([0] => stdClass Object ([term_id] => 44 
                               [name] => Escritórios comerciais 
                               [slug] => escritorios-comerciais 
                               [term_group] => 0 [term_order] => 1 
                               [term_taxonomy_id] => 44 
                               [taxonomy] => area 
                               [description] => 
                               [parent] => 33 
                               [count] => 0) 
       [1] => stdClass Object ([term_id] => 45 
                               [name] => Escritórios de advocacia 
                               [slug] => escritorios-de-advocacia 
                               [term_group] => 0 
                               [term_order] => 2 
                               [term_taxonomy_id] => 45 
                               [taxonomy] => area 
                               [description] => 
                               [parent] => 33 
                               [count] => 0) 
       [2] => stdClass Object ([term_id] => 46 
                               [name] => Sede administrativa 
                               [slug] => sede-administrativa 
                               [term_group] => 0 
                               [term_order] => 3 
                               [term_taxonomy_id] => 46 
                               [taxonomy] => area 
                               [description] => 
                               [parent] => 33 
                               [count] => 0) 
       [3] => stdClass Object ([term_id] => 47 
                               [name] => Alimentação 
                               [slug] => alimentacao 
                               [term_group] => 0 
                               [term_order] => 4 
                               [term_taxonomy_id] => 47 
                               [taxonomy] => area 
                               [description] => 
                               [parent] => 33 
                               [count] => 0) 
       [4] => stdClass Object ([term_id] => 48 
                               [name] => Indústria 
                               [slug] => industria 
                               [term_group] => 0 
                               [term_order] => 5 
                               [term_taxonomy_id] => 48 
                               [taxonomy] => area 
                               [description] => 
                               [parent] => 33 
                               [count] => 0 )) 

Is possible to create an array only with 'slug' field without using array_column?

1
  • Can you please edit the code it is nearly unreadable, put it on more than one line at least. Commented Mar 2, 2015 at 19:04

2 Answers 2

2

Use a foreach to iterate through the outer array and then just index the inner one directly.

$slugs = array();
foreach($array as $key => $value) {
    $slugs[$key] = $value->slug;
}
Sign up to request clarification or add additional context in comments.

Comments

1

This should work with array_map:

$result = array_map(function($v) { return $v->slug; }, $array);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.