ramya
ramya

Reputation: 175

how to get the value from an array

$a=Array ([storage] => [submitted] => 1 [values] => Array ( [q] => googl [op]))

How can I get the value of q from this array $a->q doesn't give me the value. Why?

Upvotes: 1

Views: 139

Answers (5)

useCase
useCase

Reputation: 1275

You use the -> on objects. For an array you need to index the variable like this:

echo $a['values']['q'];

Check this foreach tutorial for u can get more information

Upvotes: 0

dcai
dcai

Reputation: 2555

You should use $a['values']['q'].

Upvotes: 1

Naftali
Naftali

Reputation: 146360

to get it do this:

echo $a['values']['q'];

Upvotes: 0

halfdan
halfdan

Reputation: 34284

You use the -> on objects. For an array you need to index the variable like this:

echo $a['values']['q'];

Upvotes: 2

Shakti Singh
Shakti Singh

Reputation: 86476

echo $a['values']['q'];

This is 2-d array you can get value like above.

you can also use the foreach to get retrieve values of arrays.

Upvotes: 1

Related Questions