Reputation: 373
My database query is below.
$beneficiary_id = DB::select('select Telephone from item ');
This returns a json array looks like this
[{"Telephone":"0111222333"},{"Telephone":"0112211223"},{"Telephone":"012345557"},{"Telephone":"0225545455"}]
For another database insertion operation I need only the telephone numbers.
I have used json_decode()
function, it is working only if we enter the array manually.
How to get only those values to another array?
Thanks in advance.
Upvotes: 0
Views: 2042
Reputation: 939
Use the pluck function
If you would like to retrieve an array containing the values of a single column, you may use the pluck method.
$titles = DB::table('roles')->pluck('title');
foreach ($titles as $title) {
echo $title;
}
Upvotes: 2