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 |
| [EMAIL PROTECTED]                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

-- 
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]

Reply via email to