getting values from multi-dimensional arrays
Posted: Thu Apr 08, 2004 7:35 am
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,
$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,