From query I got a multidimensional array. Later I need to sort this array to provide a response to the user. I want to sort the array based on position. I'm not able to do it using a foreach / for loop.
Code:
$getImages = $this->event_model->getpromotinaldataAll();
$getOffers = $this->event_model->getAllOffersdata();
foreach($getImages as $row) {
$tmp = array();
$tmp['id'] = $row->pid;
$tmp['name'] = $row->partnername;
$tmp['latitude'] = $row->latitude;
$tmp['longitude'] = $row->longitude;
$tmp['image_url'] = $url.$row->image;
//$tmp['date'] = $row->created_at;
$tmp['type'] = $row->type;
$tmp['position'] = $row->position;
$tmp['objectId'] = $row->couponId;
$tmp['actionTitle'] = $row->actionTitle;
array_push($response, $tmp);
}
foreach($getOffers as $row) {
$tmp = array();
$tmp['id'] = $row->id;
$tmp['name'] = $row->name;
$tmp['latitude'] = "";
$tmp['longitude'] = "";
$tmp['image_url'] = $url.$row->image;
//$tmp['date'] = $row->date;
$tmp['type'] = $row->type;
$tmp['position'] = $row->position;
$tmp['objectId'] = $row->eventId;
$tmp['actionTitle'] = $row->actionTitle;
array_push($response, $tmp);
}
Output:
Array
(
[0] => Array
(
[id] => 2
[name] => Saltocean
[latitude] => 12.913510
[longitude] => 77.487395
[image_url] =>
[type] => 1
[position] => 2
[objectId] => 3
[actionTitle] => Create Invite
)
[1] => Array
(
[id] => 1
[name] => saurabh hotel
[latitude] => 28.6466759
[longitude] => 76.8123909
[image_url] =>
[type] => 1
[position] => 4
[objectId] => 4
[actionTitle] => Create Invite
)
[2] => Array
(
[id] => 5
[name] => trial
[latitude] =>
[longitude] =>
[image_url] =>
[type] => 2
[position] => 2
[objectId] => 4
[actionTitle] => Invite Me
)
[3] => Array
(
[id] => 6
[name] => trial
[latitude] =>
[longitude] =>
[image_url] =>
[type] => 2
[position] => 1
[objectId] => 4
[actionTitle] => Invite Me
)
)