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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -