Page 1 of 1

array quick q

Posted: Sat Jan 22, 2005 10:36 pm
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?

Posted: Sat Jan 22, 2005 10:53 pm
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.