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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 />"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.