php loop through array -


i trying values array got stuck. here how array looks:

array(2) {   [0]=>   array(2) {     ["attribute_code"]=>     string(12) "manufacturer"     ["attribute_value"]=>     string(3) "205"   }   [1]=>   array(2) {     ["attribute_code"]=>     string(10) "silhouette"     ["attribute_value"]=>     array(1) {       [0]=>       string(3) "169"     }   } } 

so have attribute_values, , insert new array, in example need 205 , 169. problem attribute_value can array or string. have right gets me first value - 205.

foreach ($array $k => $v) {   $vmine[] = $v['attribute_value']; } 

what missing here?

thank you!

i suggest use array_map instead of for loop. can try this..

$vmine = array_map(function($v) {     return is_array($v['attribute_value']) ? current($v['attribute_value']) : $v['attribute_value']; }, $arr);  print '<pre>'; print_r($vmine); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -