I have 2 tables i.e user
and photo
. According to user_id
get all the user details and all the photos from the photo table.
I am creating a web-service using slim framework. How is it possible to make a array like above given format?
How to make a array like following format?
array(
[id]=>
[name]=>
[email]=>
[dob]=>
[gallery]=>array(
[0] => 1.png
[1] => 2.png
)
[address]=> xyz
)
If your question is strictly about how to make the nested array, then here is a solution.
// create the nested portion of the array
$images = ['1.png', '2.png'];
// create the rest of the array
$result = [
'id' => 1,
'name' => 'default',
'email' => '123@abc.com',
'dob' => '3/4/89',
'gallery' => $images,
'address' => 'xyz'
];
Note how we set 'gallery' => $images
. If you need data from two different tables to be retrieved at the same time and formatted like this, then that would probably be easiest to achieve using a join in your query. If you need help with that just say so.