Friday, 15 March 2013

php - Proper way to get data from multi dim array -



php - Proper way to get data from multi dim array -

hi next array data:

i trying highlighted part of picture.

this associative array far have tried this:

<?php for($i = 0 ; $i < count($ad['all_atr']) ; $i++) { $atr_n= $ad[$i]['all_atr']['atr_n']; $atr_v= $ad[$i]['all_atr']['atr_v']; ?> <tr> <td><?php echo $atr_n;?></td> <td><?php echo $atr_v;?></td> </tr> <?php ....

but gives error 'undefined offset: 0'

to access it, point array first, index:

for($i = 0; $i < count($ad['all_atr']); $i++) { $atr_n = $ad['all_atr'][$i]['a_name']; $atr_v = $ad['all_atr'][$i]['a_val']; }

or using foreach:

foreach($ad['all_atr'] $values) { $atr_n = $values['a_name']; $atr_v = $values['a_val']; }

php arrays associative-array

No comments:

Post a Comment