<?php
$str = '{"Body":
{"stkCallback":
{"MerchantRequestID":"26452-605723-2","CheckoutRequestID":"ws_CO_23042018105859659","ResultCode":0,"ResultDesc":"The service request is processed successfully.","CallbackMetadata":
{"Item":[{"Name":"Amount","Value":1.00},{"Name":"MpesaReceiptNumber","Value":"MDN6ZJE4XG"},{"Name":"Balance"},{"Name":"TransactionDate","Value":20180423105912},{"Name":"PhoneNumber","Value":254722200121}]}}}}';
$arr = json_decode($str,true);
echo $arr['Body']['stkCallback']['MerchantRequestID'] . "\n"; // Working
//echo $arr['Body']['stkCallback']['CallbackMetadata'] . "\n";
echo $arr['Body']['stkCallback']['CallbackMetadata']['Item'][1]['Value'] . "\n";
echo $arr['Body']['stkCallback']['CallbackMetadata']['Item'][3]['Value'] . "\n";
echo $arr['Body']['stkCallback']['CallbackMetadata']['Item'][4]['Value'] . "\n";
echo $arr['Body']['stkCallback']['CallbackMetadata']['Item'][0]['Value'] ."\n";
/*Foreach($arr['Body']['stkCallback']['CallbackMetadata']['Item'] as $subarr){
Foreach($subarr as $item){
Echo $item ."\n";
}
} */
- Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
- 26452-605723-2
MDN6ZJE4XG
20180423105912
254722200121
1
preferences:
44.17 ms | 407 KiB | 5 Q