In xx.php I create a muti-dimensional array as follows:
$result = mysql_query('SELECT * FROM country');
$country = array();
while($row = mysql_fetch_assoc($result)) {
$country[$row['country_id']] = array('country'=>$row['country'],
'language'=>$row['language']);
}
and post this array with
<input type=hidden name=country value="<?php echo print_r($country); ?>" >
to the next page with post method. When I do the following :
print_r($country); - I get:
Array ( [1] => Array ( [country] => UK [language] => English ) [2] => Array ( [country] => Iran [language] => Persian ) [3] => Array ( [country] => Spain [language] => Spanish ) [4] => Array ( [country] => Germany [language] => German ) ) 1
However I have two questions:
1 - can not somehow get each ingredient, think Im lost in the syntax somehow?? F. ex how do i get all the specific values f.ex for [1] language? an so on...
2 - Is it the 'usual' way to post an array as
<input type=hidden name=country value="<?php echo print_r($country); ?>" >
thanks,
getting values from multi-dimensional arrays
Moderator: General Moderators
If you really want to post an array like that then you should use serialize and on the 'receiving' page use unserialize to get it back again (instead of using print_r which is just a raw dump).