4

I have 2 columns id = [10 , 22 , 31]; and loction_url = [123.456 , 654.325 , 632,983]; i want data into a single array like this $a = [10 => 123.456 , 22 => 654.325 , 31 => 632,983];

here is my query which only gets columns

$customers = Customer::whereIn('created_by', $adminot)->select(array('id' , 'location_url'))->get();
1

2 Answers 2

6

This is what Collection::pluck is for:

$customers = Customer::whereIn('created_by', $adminot)
    ->select(array('id' , 'location_url'))
    ->get()
    ->pluck('location_url', 'id');

It'll return an associative array where the key is the value of id and it's respective value is the value of location_url.

Sign up to request clarification or add additional context in comments.

Comments

0

you can use array_merge like

$a = array_merge($id,$loction_url)

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.