RE: [PHP] list(), each()

2002-03-25 Thread Rick Emery

change to:
list( $policy_num, $policy_year, $application_reference ) = explode( "--",
$policy ); 


-Original Message-
From: Chris Boget [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 25, 2002 11:22 AM
To: PHP General
Subject: [PHP] list(), each()


Ok, I've got to be doing something wrong here.  I've been
beating my head up against the wall for some time and I 
just cannot figure out what it is.  Before I say it's a bug with
list(), could someone tell me what I'm doing wrong?

\n";

// fine
$policy = explode( "--", $policy );
echo $policy[0] . "\n";
echo $policy[1] . "\n";
echo $policy[2] . "\n";

?>

Why isn't list() assigning the value properly?  For the first echo
statement, I'm
getting:  

"list( 0, 1016726726, ) = each( explode( "--", 1016726726--1--1016643856
));"

but the others, where I'm echoing out the individual elements, it's working
fine.

What's going on?

Chris



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] list(), each()

2002-03-25 Thread Chris Boget

> Why do you put each(explode()) ?  Just list() = explode() is what you
> want.

I did that because I thought they were complimentary functions?  Just about
every example I've seen of list() uses each().  Just using explode() makes it
work.  Obviously I'm going to have to go back and read more about list().

thnx,
Chris


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] list(), each()

2002-03-25 Thread Rasmus Lerdorf

Why do you put each(explode()) ?  Just list() = explode() is what you
want.

-Rasmus

On Mon, 25 Mar 2002, Chris Boget wrote:

> Ok, I've got to be doing something wrong here.  I've been
> beating my head up against the wall for some time and I
> just cannot figure out what it is.  Before I say it's a bug with
> list(), could someone tell me what I'm doing wrong?
>
> 
> $policy = "1016726726--1--1016643856";
>
> // problematic
> list( $policy_num, $policy_year, $application_reference ) = each( explode( "--", 
>$policy ));
> echo "list( $policy_num, $policy_year, $application_reference ) = each( explode( 
>\"--\", $policy )); \n";
>
> // fine
> $policy = explode( "--", $policy );
> echo $policy[0] . "\n";
> echo $policy[1] . "\n";
> echo $policy[2] . "\n";
>
> ?>
>
> Why isn't list() assigning the value properly?  For the first echo statement, I'm
> getting:
>
> "list( 0, 1016726726, ) = each( explode( "--", 1016726726--1--1016643856 ));"
>
> but the others, where I'm echoing out the individual elements, it's working fine.
>
> What's going on?
>
> Chris
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] list() = each() Question

2001-02-07 Thread Jason Mowat

Hehehe,

I searched around on PHP.net, and found this tidbit of information.  It
sounds to me that list() is written to only accept the first two elements
from the each().  Please correct me if I am misinformed :-)

Cheers,
Jason

[EMAIL PROTECTED]
16-Feb-2000 03:41

Ok, for you folks who are learning this, here's something that should help
your comprehension of each(), because I bashed my brains for a while on this
one.

The first example indicates that each() spits out a 4-cell 1 dimensional
array. This is all fine and dandy until you get to the second example, where
that seems to be thrown out the window, because though each() is still
spitting out 4 array elements, the list() being used is set up to only
accept 2 values, as it's being executed with only wo variables in it!

For some folks, this might not be a problem, but I couldn't understand the
mismatch - why was it done, and where did the array go that each()
generated?? Well, upon executing that code, it turns out that the first two
array elements of the 4 element array that each() creates are assigned to
those two variables, and the last two array element values are just thrown
away - they're totally ignored. It's how PHP is written.

Now, why do that? Well, the example was definitely written more to show
folks how to use each() to make life much easier when dealing with a
particular operations array in PHP that a lot of people work with, but it
also has the side effect (which hopefully my little explaination has made
more palatable) of demonstrating how each() can act when being used with
other functions that don't necessarily want all of each()'s input.

""Jason Mowat"" <[EMAIL PROTECTED]> wrote in message
95rrbg$p3i$[EMAIL PROTECTED]">news:95rrbg$p3i$[EMAIL PROTECTED]...
> Greets,
>
> I have a quick question:
>
> $Array = array(
>  "val1" => "Value 1",
>  "val2" => "Value 2",
>  "val3" => "Value 3"
> );
>
> while(list($a,$b,$c,$d) = each($Array)) {
>   print "$a = $c and $b = $d ";
> }
>
> Doesn't the "each" construct return a 4 element array, where element 1's
> index is 0, element 2's index is 1, element 3's index is "key" and element
> 4's index is "value"?  Now, if that is the case, the above should work,
> right?  I should create a list containing $a, $b, $c and $d, where $a and
$c
> contain key information, and $b and $d contain value information?  For
some
> reason, $c and $d are NULL...
>
> What am I missing here?
>
> Cheers,
> Jason
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]