ainoy31 Posted December 14, 2007 Share Posted December 14, 2007 Hello- I believe my brain is fryed and seem to not be able to think this through. I need help with the following. I have two dynamic arrays. The first array will contain the commodity name such as $comm = Array ( [0] => X [1] => Y [2] => [3] => ... and so forth). The second array contains an unique number to each commodity such as $htsus = Array ( [0] => 12345 [1] => 6789 [2] => ... and so forth). I need to get the format to display as follows: Commodity: X HTSUS: 12345 Commodity: Y HTSUS: 6789 ..... I have tried using the foreach function but no luck. foreach($comm as $var) { echo "Commodity: " . $var . ' '; foreach($htsus as $data) { echo "HTSUS: " . $data <br />"; } } Much appreciation.. AM Link to comment https://forums.phpfreaks.com/topic/81732-solved-arrays/ Share on other sites More sharing options...
kenrbnsn Posted December 14, 2007 Share Posted December 14, 2007 If it's always a 1 to 1 match between the arrays you can do: <?php for($i=0;$i<count($comm);$i++) echo 'Commdity: ' . $comm[$i] . ' HTSUS: ' . $htsus[$i] . "<br>\n"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/81732-solved-arrays/#findComment-415086 Share on other sites More sharing options...
ainoy31 Posted December 14, 2007 Author Share Posted December 14, 2007 Yes it is and thank you. AM Link to comment https://forums.phpfreaks.com/topic/81732-solved-arrays/#findComment-415089 Share on other sites More sharing options...
lemmin Posted December 14, 2007 Share Posted December 14, 2007 You could use two dimensions like: $comm = array(array('X',12345), array('Y',6789)); Or even like this if you want to name the keys: $comm = array(array("name" => 'x',"uniqid" => 12345), array("name" => 'Y',"uniqid" => 6789)); I think it would be easier. Do a print_r($comm) to visualize it. Link to comment https://forums.phpfreaks.com/topic/81732-solved-arrays/#findComment-415090 Share on other sites More sharing options...
PFMaBiSmAd Posted December 14, 2007 Share Posted December 14, 2007 Also, - <?php foreach($comm as $key => $var) { echo "Commodity: $var HTSUS: {$htsus[$key])<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/81732-solved-arrays/#findComment-415092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.