I have an array like this:
array (size=2)
'status' => string 'ok' (length=2)
'data' =>
array (size=5)
'sort_data' =>
array (size=2)
'sort_column' => string 'order_item_id' (length=13)
'sort_order' => string 'asc' (length=3)
Now I coded this for getting sort_column
and it's value and also sort_order
and it's value:
$status = $response['status'];
if($status == 'ok'){
$nums = count($response['data']['sort_data']); //retrieves 2
for($i=0; $i<=$nums; $i++){
foreach($response['data']['sort_data'][$i] as $key=>$value){
echo $key."=".$value;
}
}
}
But I get these errors:
Notice: Undefined offset: 0 on line 6
Warning: Invalid argument supplied for foreach() on line 6
Line 6:
foreach($response['data']['sort_data'][$i] as $key=>$value){
So what is going wrong here?
How can I get the contents of sort_data
within this foreach
properly?
UPDATE #1:
Array
(
[status] => ok
[data] => Array
(
[sort_data] => Array
(
[sort_column] => order_item_id
[sort_order] => asc
)