PHP while inside while -


let's i'm trying combine items 2 lists, , want result:

a7
a8
b7
b8

this code:

<?php  $list1_array = array('a', 'b'); $list2_array = array('7', '8');  while(list( , $item1) = each($list1_array)) {          while(list( , $item2) = each($list2_array)) {       echo $item1.$item2."<br />";       } }  ?> 

i result:

a7
a8

i seems outside 'while' doesn't make second loop? doing wrong?

while might better use more common (perhaps more readable) approach (e.g. using foreach loops as shown goleztrol,) in answer original questions:

the problem happening because internal "cursor" (or "pointer") array not being reset... never gets start of original array.

instead, if try this:

<?php     $list1_array = array('a', 'b'); $list2_array = array('7', '8');  while(list(,$item1) = each($list1_array)) {        while(list(,$item2) = each($list2_array)) {       echo $item1.$item2."<br />";     }     reset($list2_array); } ?> 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -