mercredi 25 février 2015

Can you access value in multi-dimensional array in one swoop?


Using get_post_meta(), you can retrieve all meta fields in one query.


Example



$post_meta = get_post_meta( $post->ID );


When you var_dump, you see



array(1) {
["device_width"]=>
array(1) {
[0]=>
string(4) "2.60"
}
}


Is there a way to access the "2.60" variable without putting the second array into it's own variable?


I know you can do:



$device_width = $post_meta['device_width'];
echo $device_width[0];


But can I access the end variable in one swoop without creating a $device_width variable? (like how you do with objects - $object->item->single)





Aucun commentaire:

Enregistrer un commentaire