RynMan Posted April 2, 2010 Share Posted April 2, 2010 Hi guys Here's my code: <?php foreach ($LNames as $val) { echo "it=s2.addItem(5,6,7,'$val',n,n,'','',n,n,n,n,n,112,20,2,0,0);\n"; } ?> What I also want to do here, is have another variable adding values from another array. Here's essentially what I want to do, but the code isn't correct..... <?php foreach ($LNames as $val and $LinkNumber as $link) { echo "it=s2.addItem(5,6,7,'$val',n,n,'$link','$link',n,n,n,n,n,112,20,2,0,0);\n"; } ?> In the earlier code, I have a loop assigning different values to an aray for $LNames. At the same time, I'm adding values to the $LinkNumber array of the same integer. So then, what I'm trying to do above, is have the following in my echo... $LNames[0] along with $LinkNumber[0] $LNames[1] along with $LinkNumber[1] $LNames[2] along with $LinkNumber[2] and so on...... Thanks for any help guys Quote Link to comment Share on other sites More sharing options...
salathe Posted April 2, 2010 Share Posted April 2, 2010 You can get the array index (key) for the array in a foreach by using the construct as key => value (see below). foreach ($LNames as $key => $val) { $link = $LinkNumber[$key]; echo "it=s2.addItem(5,6,7,'$val',n,n,'$link','$link',n,n,n,n,n,112,20,2,0,0);\n"; } Hope that helps. Quote Link to comment Share on other sites More sharing options...
ignace Posted April 2, 2010 Share Posted April 2, 2010 If both arrays have different key indexes, you could alternatively use: while (next($array1) && next($array2)) { 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.