Reputation: 773
I have an array like:
[meta] => Array (
[company] => Company, LLC
[confirmation] => 6391381
[reference] => None
[service] => Service
[timestamp] => 2016-04-25 11:12:54
[user] => company
)
[result] => Array (
[action] => REVIEW
[detail] => TRANSACTION REQUIRES FURTHER ATTENTION
[issues] => Array (
[0] => DOB CHECK FAILED
)
)
[output] => Array ( )
I am attempting to echo the 'action' value like this:
$json_result = json_decode($result, true);
echo "$json_result[result]['action']";
But instead of getting 'REVIEW' I am getting: 'Array['action']'
Any thoughts?
Upvotes: 0
Views: 516
Reputation: 3074
You're missing the apostrophes from the first index:
$json_result[result]['action'];
It should look like this:
$json_result['result']['action'];
^ ^
Edit: You can use regular php syntax to address array values if you put the whole expression between curly braces ( { ):
echo "This is the result: {$json_result['result']['action']};"
...or simply remove the double quotes (") from echo.
More info here: php echo
Upvotes: 1
Reputation: 3531
using arrays inside strings leads to madness. or at least horrible frustration.
as Jon Stirling pointed out, in your case why even bother putting the variable in a double quote?
echo $json_result['result']['action'];
works just fine. If you must use an array inside a string, escape it with curly braces
echo "{$json_result['result']['action']}";
Upvotes: 2
Reputation: 116
To review all array
print_r($json_result);
To view only action
echo $json_result['result']['action'];
Upvotes: 0