Reputation: 73
How do I echo the 4 at the bottom?
$request_body = '{"id":8801236,"order_id":"1854071","accepted":true,"type":"Payment","text_on_statement":null,"branding_id":null,"variables":{},"currency":"USD","state":"pending","operations":
[{"id":1,"type":"authorize","amount":8996,"pending":false,"qp_status_code":"20000","qp_status_msg":"Approved","aq_status_code":"000","aq_status_msg":"Approved","data":
{},"callback_url":"http://www.mywebsite/callback.php","callback_success":true,"callback_response_code":"200","created_at":"2015-11-11T13:32:22+00:00"},
{"id":2,"type":"capture","amount":8863,"pending":true,"qp_status_code":null,"qp_status_msg":null,"aq_status_code":null,"aq_status_msg":null,"data":
{},"callback_url":null,"callback_success":null,"callback_response_code":null,"created_at":"2015-11-11T14:37:18+00:00"}],"metadata":
{"type":"card","brand":"visa","last4":"0008","exp_month":1,"exp_year":2019,"country":"US","is_3d_secure":false,"hash":"fdsfsdfsdf4ds65f4dsf65ds4"
,"number":null,"customer_ip":"8.1.1.21","customer_country":"US","fraud_suspected":false,"fraud_remarks":
[]},"link":null,"shipping_address":null,"invoice_address":null,"test_mode":true,"acquirer":"nets","facilitator":null,"created_at":"2015-11-11T13:32:13Z","balance":0}';
$request_array = json_decode($request_body, TRUE);
echo $request_array['qp_status_code']."<br />";
echo $request_array['qp_status_msg']."<br />";
echo $request_array['aq_status_code']."<br />";
echo $request_array['aq_status_msg']."<br />";
I have tried to do a print_r on the request_array, but honestly that only confuses me more. I simply can not see what array these variable lies within. I have tried to call them with both variables and operations but alas.
Upvotes: 0
Views: 47
Reputation: 2051
Your JSON feed has more than one "operations" which means you can call them like this (to get the first only):
echo $request_array['operations'][0]['qp_status_code']."<br />";
echo $request_array['operations'][0]['qp_status_msg']."<br />";
echo $request_array['operations'][0]['aq_status_code']."<br />";
echo $request_array['operations'][0]['aq_status_msg']."<br />";
Or if you need all of them you need to loop in it:
foreach ($request_array['operations'] as $operation) {
echo $operation['aq_status_msg']."<br />";
}
Upvotes: 1