array quick q

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

array quick q

Post by shiznatix »

ok i have 2 arrays
the 1st array looks like this aaa,bbb,ccc,ddd
the 2nd array looks like this 1,4,3,7

i want the output to be this

aaa - 1
bbb - 4
ccc - 3
ddd - 7

i tried a foreach loop inside another foreach loop but that clearly was not the answer. any sugestions?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

two ways

Code: Select all

for($i = 0, $j = count($arr1); $i < $j; $i++)
  echo $arr1&#1111;$i] . ' - ' . $arr2&#1111;$i] . "\n";

Code: Select all

foreach($arr1 as $i => $v)
  echo $v . ' - ' . $arr2&#1111;$i] . "\n";
both requires numeric indices in the arrays.
Post Reply