Re: elementary question about reading an array ...
| From: | Red Wingate | Date: | Thu, 01 Apr 2004 16:52:55 +0000 |
| Subject: | Re: elementary question about reading an array ... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182036@lists.php.net to get a copy of this message | ||
Yet again maybe one would check the output before replying:
Array (
[0] => bc Object (
[fullname] => Kent Huffman
...
)
)
This is what we see:
echo $db['fullname']; // nope
echo $db[0]->fullname // ahhhhh !!!
-- red
Kenn Murrah wrote:
[snip]
[snip] In code that I did not create (and do not entirely understand), an array ($db) was created which, if displayed with print_r($db), shows the following: Array ( [0] => bc Object ( [fullname] => Kent Huffman [industry] => Technology Solutions [url] => /tsi [address1] => 2300 W. Plano Parkway [city] => Plano [state] => TX [zip] => 75075 [country] => USA [direct] => +1 (972) 577 3890 [email] => kent.huffman@ps.net [orderID] => PSC5 [financialdeptID] => MARCO10 [quantity] => 250 [messagetoprinter] => [shippingmethod] => FedEx Express Saver [ship2name] => Kent Huffman [ship2address1] => 2300 W. Plano Parkway [ship2address2] => [ship2city] => Plano [ship2state] => TX [ship2zip] => 75075 [ship2country] => USA [ship2phone] => +1 (972) 577 3890 ) ) My elementary question is: how do I reference one item in the array? For instance, if I want $fullname = "Kent Huffman" how can I write that statement? I thought $fullname = $db[0]['fullname' would work. It obviously doesn't, and I've tried a dozen other things, including RTFM and several other tutorials, to no avail. [/snip] this will display a single element $fullname = $db['fullname']; echo fullname; you can just echo $db['fullname'];That's what I thought at first, but that's not working ... in fact, I just copied and pasted both your snippets, and neither of them worked here .... odd, isn't it? What the heck am I doing wrong here ? [snip]