I have an array that looks like the following:
Data = array(
'Offer' => array(),
'Country' = array('Name' => Array())
)
Now if i want to sort on the value of the first item of the Name
array how would i go around that?
Ive tried this so far:
$dataArray = $originalData['data'];
$dataArray = Set::sort($dataArray, '{n}.Country.Name', $direction);
However this did not work
Note im using CakePHP set::Sort
is a part of Cakephp
Okay seems i wasnt clear enough so here is a more detailed explaination of my problem:
So ive created my own datasource in cake that collects data from an API.
The API returns data in a way that looks like this:
data = array(
'Offer' => array('id' => 2, 'name' = 'ExampleName'),
'Stat' => array('Stat1' = 1, 'Stat2' = 2),
'Country => array('Name' => array('name1','name2')
);
Now in order to make the user able to sort these data i have to make sure that i display correctly.
This works fine when there is only one value i.e:
$dataArray = $originalData['data'];
$dataArray = Set::sort($dataArray, '{n}.Stat.Stat1', 'ASC);
$originalData['data'] = $dataArray;
However country is an array so in order to "copy" the code above i need to use the first item of the Country['Name'] array.
to do something like this:
$dataArray = $originalData['data'];
$dataArray = Set::sort($dataArray, '{n}.Country.Name', $direction);
$originalData['data'] = $dataArray;
However the above code is failing ...