Click to See Complete Forum and Search --> : wierd output


theevilblah
01-10-2003, 11:54 PM
Hey guys,

In PHP I made an array as follows


<?php
$crew = array (
"Name" => array ("Ilya"),
"age" => array (13),
"location" => array ("San Diego, Ca")
);
echo "$crew";
?>



When I test it, all that happens is it says "Array"
(without the quotes)

I was wondering why it does this and what is wrong with my array?

Thanks,

Ilya


P.S. Dont laugh at my code, i know it probably really buggy.

BTW. I googled on this for about 1 hour and even used the example from php.net and got the same results.

iDxMan
01-14-2003, 01:03 AM
<pre>
<?php
print_r($crew);
//** or **/
vardump($crew);
?>
</pre>


To echo a specific field you need to refer to that element - not the entire array. eg:


echo $crew["Name"][0];


-r

nouse66
01-14-2003, 01:40 AM
the examples on php.net do show a way to output the whole array but its not pretty...

if you use print_r($crew); you get this output:

Array ( [Name] => Array ( [0] => Ilya ) [age] => Array ( [0] => 13 ) [location] => Array ( [0] => San Diego, Ca ) )

you probably want to just use a little loop to get nice formatted output.