I have an url that gives me this result:
{"status":"ok","result":[{"account":"11754-101","name":"test","channels":"15","billing":"1","billingstep":"60","increment":"0","credit":"1.0089"},{"account":"11754-102","name":"mult","channels":"15","billing":"1","billingstep":"60","increment":"0","credit":"2.7835"}]}
I'm trying to get the "credit" value of just one account to view it.
Account: 11754-102
Credit: XXX
The code I did is this, but it seems to be broken:
<?php
$json = '{"status":"ok","result":[{"account":"11754-101","name":"test","channels":"15","billing":"1","billingstep":"60","increment":"0","credit":"1.0089"},{"account":"11754-102","name":"mult","channels":"15","billing":"1","billingstep":"60","increment":"0","credit":"2.7835"}]}';
$apiResult = json_decode($json, true);
($apiResult['status'] !== 'ok') &&
trigger_error('Unexpected API Result');
empty(($account = array_filter($apiResult['result'], function($item) {
return $item['account'] === '11754-102';
}))) && trigger_error('Account not found.');
echo $account[0]['credit'];
?>
Can you help me?