samedi 7 janvier 2017

How to add key value pair in objects of array in laravel.

I am getting following code as output in laravel.

[  {"id":"1","name":"Mite Salary"},  {"id":"2","name":"Riky"},  {"id":"3","name":"Raj"}  ]

I want to add another key-value pair of age:person_age and want output as

[  {"id":"1","name":"Mite Salary", "age":'20'},  {"id":"2","name":"Riky", "age":'25'},  {"id":"3","name":"Raj", "age":"40"}  ]

This age is coming from mysql database as $y = DB::table("age")->get(); For now considering $y=[20,25,40];

But I m not getting how to do it with foreach loop. Kindly help me in this. Thanking you in anticipation



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2i28VOs
via IFTTT

Aucun commentaire:

Enregistrer un commentaire