Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can just do something like this</p> <pre><code>foreach($apiResult['WHMCSAPI']['DEPARTMENTS'] as $department) { echo $department['NAME'].' has '.$department['AWAITINGREPLY'].' cases awaiting reply.'&lt;br /&gt;'; } </code></pre> <p>See a full demo code here: <a href="http://phpfiddle.org/main/code/0c4-pgs" rel="nofollow">http://phpfiddle.org/main/code/0c4-pgs</a></p> <hr> <p>Updated answer for: "Any ideas on how I can the output by the AWAITING reply value? ie: If Sales has 10 tickets, and Support has 12 show Support above Sales, and vise versa? – cbcp"</p> <p>Here you can use a get variable to define sort. url.domain/mypage.php?sort=desc | url.domain/mypage.php?sort=asc</p> <pre><code>try { $apiResult = array('WHMCSAPI' =&gt; array( 'ACTION' =&gt; 'getsupportdepartments', 'RESULT' =&gt; 'success', 'TOTALRESULTS' =&gt; 2, 'DEPARTMENTS' =&gt; array( 'DEPARTMENT' =&gt; array( 'ID' =&gt; 2, 'NAME' =&gt; 'Sales', 'AWAITINGREPLY' =&gt; 5, 'OPENTICKETS' =&gt; 5 ), 'DEPARTMENT1' =&gt; array( 'ID' =&gt; 1, 'NAME' =&gt; 'Support', 'AWAITINGREPLY' =&gt; 15, 'OPENTICKETS' =&gt; 15 ) ) ) ); echo '&lt;pre&gt;'; print_r($apiResult); echo '&lt;/pre&gt;'; if($apiResult['WHMCSAPI']['RESULT'] != 'success') { throw new Exception('Something went wrong while fetching the data.'); } if(!isset($apiResult['WHMCSAPI']['DEPARTMENTS'])) { throw new Exception('No departments in API response.'); } if(!empty($_GET['sort'])) { $tmpArray = array(); foreach($apiResult['WHMCSAPI']['DEPARTMENTS'] as $key =&gt; $value) { $tmpArray[$value['AWAITINGREPLY']] = $value; } $apiResult['WHMCSAPI']['DEPARTMENTS'] = $tmpArray; ($_GET['sort'] == 'desc') ? krsort($apiResult['WHMCSAPI']['DEPARTMENTS']) : ksort($apiResult['WHMCSAPI']['DEPARTMENTS']); } foreach($apiResult['WHMCSAPI']['DEPARTMENTS'] as $department) { echo $department['NAME'].' has '.$department['AWAITINGREPLY'].' cases awaiting reply.&lt;br /&gt;'; } } catch (Exception $exc) { echo $exc; } </code></pre> <p>If you'd rather have a default sort then you should just modify it to suit your needs.</p> <pre><code>if(!empty($_GET['sort'])) { $tmpArray = array(); foreach($apiResult['WHMCSAPI']['DEPARTMENTS'] as $key =&gt; $value) { $tmpArray[$value['AWAITINGREPLY']] = $value; } $apiResult['WHMCSAPI']['DEPARTMENTS'] = $tmpArray; ($_GET['sort'] == 'desc') ? krsort($apiResult['WHMCSAPI']['DEPARTMENTS']) : ksort($apiResult['WHMCSAPI']['DEPARTMENTS']); } </code></pre> <p>---></p> <pre><code>$tmpArray = array(); foreach($apiResult['WHMCSAPI']['DEPARTMENTS'] as $key =&gt; $value) { $tmpArray[$value['AWAITINGREPLY']] = $value; } $apiResult['WHMCSAPI']['DEPARTMENTS'] = $tmpArray; krsort($apiResult['WHMCSAPI']['DEPARTMENTS']); </code></pre> <p>This will sort the departments like you requested.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload