Troy Cosentino
Troy Cosentino

Reputation: 4778

how to get a value from a returned JSON array

If i have:

print_r($request->getRequestVars());

that prints out:

Array ( [n] => Coors [s] => 3 ) 

how would i print out coors?

echo $request->getRequestVars()->n;

is not working, and i've tried several other things. I know this is super basic but it's frustrating me

Upvotes: 0

Views: 66

Answers (3)

Baba
Baba

Reputation: 95161

Please note that $request->getRequestVars() returns array not object. PHP 5.4 has Function Array Dereferencing if that is what you are running then you can have:

echo $request->getRequestVars()['n'];

else

$v = $request->getRequestVars();
echo $v['n'];

Upvotes: 2

Darius
Darius

Reputation: 612

Try:

<?php

$var = $request->getRequestVars();
echo $var['n'];

?>

Upvotes: 2

Mart&#237;n Peverelli
Mart&#237;n Peverelli

Reputation: 328

I assume that the method $request->getRequestVars(); acutally returns an array. So, you would have to do something along the lines of:

$foo = $request->getRequestVars();
echo $foo['n'];

Upvotes: 2

Related Questions