Jump to content

[SOLVED] Foreach loop with logical operator?


bluebyyou

Recommended Posts

Unfortunately, no.  Here are two alternate styles.

 

# This one only works for arrays numbered consecutively from 0
$i = 0;
$arr_len = count($arr);
for ($i = 0; $i < $arr_len; $i++) {
  print $arr[$i];
  print $arr2[$i];
}

 

# This one works for anything
reset($arr);
reset($arr2);
while (list($arr_key, $arr_val) = each($arr)) {
  list($arr2_key, $arr2_val) = each($arr2);
}

 

In both cases, the length of the loop is decided by the length of $arr, in the case of a mismatch in array lengths.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.