Re: How do I see the data in list()?

From: Date: Thu, 25 Jan 2001 17:38:38 +0000
Subject: Re: How do I see the data in list()?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36667@lists.php.net to get a copy of this message
At 11:33 AM -0500 1/25/01, Scott Fletcher wrote:
Hi!
    When I use the echo to see what is inside the list().  Instead I got the
message on screen saying "ArrayArray".
    The array are being assigned first then then list come second.  ie.
        $test = array();
        $test1 = array()
        list($test,$test1);
---------------
    When I do "echo list($test,$test1);", it doesn't work.
    What are the better way to see the data in the array?
Are these actual program snippets? If they are then (1) '$test1 = array()' line is missing a trailing ';' (2) The statement 'list($test,$test1);', to the best of my knowledge, does nothing in this context. (3) From your echo statement, you should see the output 'list(Array,Array)' - functions and language constructs aren't evaluated in double-quoted strings; only variables. It would make more sense to me to have something like $test = array('bean', 'noodle', 'wednesday'); $test1 = array('a'=>'apple', 'b'=>'banana', 'c'=>'carrot'); $foo = array($test, $test1); Then you could display these values like so: If you have PHP4, use print_r() or var_dump(): echo print_r($foo); See http://www.php.net/manual/en/function.print-r.php http://www.php.net/manual/en/function.var-dump.php I haven't used either of these functions, so I don't know exactly what the output looks like. It says var_dump() was available in PHP 3 after 3.0.5, but I'm not entirely sure that's true. If it is, it must have been undocumented for a while. An alternative display method would be something like (a little more cumbersome, but works in PHP3 & 4): for ($i=0; $i<count($foo); $i++) { while(list($Key,$Val) = each($foo[$i])) { echo "foo[$i][$Key] = $Val<br>\n"; } } Also, instead of the $test = array('bean', 'noodle', 'wednesday'); $test1 = array('a'=>'apple', 'b'=>'banana', 'c'=>'carrot'); $foo = array($test, $test1); way of declaring the $foo array, you could also say $foo = array( array('bean', 'noodle', 'wednesday'), array('a'=>'apple', 'b'=>'banana', 'c'=>'carrot') ) or $foo[0] = array('bean', 'noodle', 'wednesday'); $foo[1] = array('a'=>'apple', 'b'=>'banana', 'c'=>'carrot'); See http://www.php.net/manual/en/language.types.array.php for more information. - steve -- +--- "They've got a cherry pie there, that'll kill ya" ------------------+ | Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-------------------------------------- FBI Special Agent Dale Cooper ---+

« previous php.general (#36667) next »