0

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.

2
  • What errors do you see when you use json_decode? Commented Jun 23, 2016 at 8:14
  • json_decode() expects parameter 1 to be string, array given. Code I have used. $tp = json_decode($beneficiary_id); return $tp; Commented Jun 23, 2016 at 8:47

2 Answers 2

2

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;
}
Sign up to request clarification or add additional context in comments.

3 Comments

when I use the method, it returns." Call to a member function pluck() on a non-object"
How you're using it? Try maybe something like this: $numbers = DB::table('item')->pluck('Telephone');
Yes, It worked.This just returns only the telephone numbers.
0

use $beneficiary_id->column_name to get the value from your object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.