elegant way to extract values from array

Posted by smoove666 on Stack Overflow See other posts from Stack Overflow or by smoove666
Published on 2010-06-01T10:46:40Z Indexed on 2010/06/01 11:03 UTC
Read the original article Hit count: 138

Filed under:
|

Something that bugs me for a long time:

I want to convert this Array:

// $article['Tags']
array(3) {
  [0] => array(2) {
    ["id"] => string(4) "1"
    ["tag"] => string(5) "tag1"
  },
  [1] => array(2) {
    ["id"] => string(4) "2"
    ["tag"] => string(5) "tag2"
  },
  [2] => array(2) {
    ["id"] => string(4) "3"
    ["tag"] => string(5) "tag3"
  },    
}

To this form:

// $extractedTags[]
array(3) {
  [0] => string(4) "tag1",
  [1] => string(4) "tag2",
  [2] => string(4) "tag3",
}

currently i am using this code:

$extractedTags = array();

foreach ($article['Tags'] as $tags) {
    $extractedTags[] = $tags['tag'];
}

Is there any more elegant way of doing this, maybe a php built-in function?

© Stack Overflow or respective owner

Related posts about php

Related posts about coding-style