Ok... I'm getting the red pen out now :) * Thus wrote CPT John W. Holmes ([EMAIL PROTECTED]): > > Hello everyone, > > Am new to php and have run into a problem while reading my book... can > anybody tell me what does this mean: > > Hi... let's see who gets this one first... :) > > > foreach($invoice as $number => $pppno) > > $invoice is an array. foreach() is going to loop through that array one > element at a time. For each element, it'll take the key and place it into > $number. It will take the value of the element and place it in $pppno. So, > if you had array('one','two'), the first element is "one" with a key of zero > (default). So, the first time through the loop, $number will be zero and > $pppno will be "one". The next time through the loop, $number will be one > and $pppno will be "two".
passed :) > > > and also this: > > > > while(list($k,$v,) = each($a)) > > Same kind of thing here, just a different method. each() loops through an > array. For each element, it'll return an array consisting of the key and > value. list() takes that array and assigns the first element of the array to > $k and the second to $v. The final while() just loops through everything > until all of the elements of $a have been run through. So, if we have our > array('one','two); again, each() will take the first element, "one", and > pass an array consisting of the key, zero, and the value, "one" to list(). > list() will assign zero to $k and "one" to $v. This one is rather confusing, and is sort of the reason why i didn't go in depth and will only give a brief summery here: the each() function returns a one element array that the current (internal) array pointer is pointing to and will return false if at the end of the array. the list() function (not really a function) takes an array on the right side of the = operator and assigns each variable its value in order returned from the array. so with the example array(0 => 'one', 1 => 'two'), the initial internal pointer is looking at the first item so when the while statement evaluates the the statement the each() function returns: 0 => 'one' This array gets returned to the list statement list($k, $v) Thus $k gets the value 0 and $v gets 'one'. Now the pointer is moved to: 1 => 'two' the loop comes back to the while and repeats the steps until the internal pointer is at the end of the array. With that being said it is almost always common to see this statement before this kind of loop because we want to make sure the pointer is at the beginning. reset($a); The foreach statement doesn't need this. > > Hope that helps. That was as much of a test for me in seeing if I could > explain it, so tell me how I did! :) I'll still give you an A :-) cheers! Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php