By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,737 Members | 1,836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,737 IT Pros & Developers. It's quick & easy.

getting values in an array of arrays

P: n/a
Hi,

The following is the output of a print_r on an array. The value of
element[0] is itself an array. How do I access the elements in the
second array?

Array ( [0] =Array ( [Vancouver] =Vancouver [Eugene] =Eugene
[Beaverton] =Beaverton ) )

I've tried to set $c[] = $city[0], but this just outputs the same
result.

Thanks,

Sal

Feb 7 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
..oO(sp******@progressivetrail.org)
>The following is the output of a print_r on an array. The value of
element[0] is itself an array. How do I access the elements in the
second array?
$foo[1st level][2nd level][3rd level]

Micha
Feb 7 '07 #2

P: n/a
On Feb 7, 9:35 am, Michael Fesser <neti...@gmx.dewrote:
.oO(spera...@progressivetrail.org)
The following is the output of a print_r on an array. The value of
element[0] is itself an array. How do I access the elements in the
second array?

$foo[1st level][2nd level][3rd level]

Micha
Hi Micha,

Thanks for the suggestion, It was the step in the right direction that
I needed to resolve the problem. The problem was that I was trying to
access the elements in the associative array by index numbers rather
than as a key/value pair. This worked:

foreach($city[0] as $key =$value) {
echo $key.'='.$value;
}
How do I get, in this example, the value of the array element with the
key "vancouver":

Array ( [0] =Array ( [Vancouver] =Vancouver [Eugene] =Eugene
[Beaverton] =Beaverton ) )
Feb 7 '07 #3

P: n/a
sp******@progressivetrail.org wrote:
Hi,

The following is the output of a print_r on an array. The value of
element[0] is itself an array. How do I access the elements in the
second array?

Array ( [0] =Array ( [Vancouver] =Vancouver [Eugene] =Eugene
[Beaverton] =Beaverton ) )

I've tried to set $c[] = $city[0], but this just outputs the same
result.

Thanks,

Sal
$myarray[0]['Vancouver']
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 7 '07 #4

P: n/a
Rik
<sp******@progressivetrail.orgwrote:
On Feb 7, 9:35 am, Michael Fesser <neti...@gmx.dewrote:
>.oO(spera...@progressivetrail.org)
>The following is the output of a print_r on an array. The value of
element[0] is itself an array. How do I access the elements in the
second array?

$foo[1st level][2nd level][3rd level]

Micha

Hi Micha,

Thanks for the suggestion, It was the step in the right direction that
I needed to resolve the problem. The problem was that I was trying to
access the elements in the associative array by index numbers rather
than as a key/value pair. This worked:

foreach($city[0] as $key =$value) {
echo $key.'='.$value;
}
How do I get, in this example, the value of the array element with the
key "vancouver":

Array ( [0] =Array ( [Vancouver] =Vancouver [Eugene] =Eugene
[Beaverton] =Beaverton ) )

$city[0]['Vancouver']

If you perhaps do not know the key names in advance you'll have to give us
a little more insight in the actual purpose.
--
Rik Wasmus
Feb 7 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.