Ali
Ali

Reputation: 91

How to use JSON data from Array

I have this result from verified transaction:

 Array ( [status] => 1 [message] => OK [user_card_no] => 6037997445418040 [amount] => 10000 [refId] => 787225 ) 

this is the function:

include_once("functions.php");
$api_token = 'My_Api_Token';
$transId = $_POST['TransId'];
$result = verify($api_token,$transId);
$result = json_decode($result,true);
print_r($result);

I tried to echo each key and value with this way:

echo $result->status;

Here is my result:

Notice: Trying to get property 'status' of non-object in /home/skyw3b/domains/sky7bet99.com/public_html/pay/verify.php on line 17

Upvotes: 1

Views: 50

Answers (1)

Teneff
Teneff

Reputation: 32158

As you can see above $result is an Array and in PHP to get a key from array you have to use

$result['status']

as you have done with $_POST['TransId'];

Upvotes: 2

Related Questions