J
J
jazzus2019-01-03 19:59:02
Laravel
jazzus, 2019-01-03 19:59:02

What is the correct way to concatenate an array and an object?

The code

//Юзер
          $user = Auth::user();
          //Телефон и вебсайт
          $contact['phone'] = $user->phone;
          $contact['website'] = $user->website;
          //Локейшен
          if (!$location=$user->location) {
             $location = new UserLocation;
          }
          //Объединяем данные
          $contact = array_merge($contact, array($location));

          return response()->json($contact);

I get
{
address:null
city_id:null
},
phone:"161421241",
website:
null an object and 2 values, and I only need the values. How to extract values ​​from an object and insert them into an array? You can, of course, manually register each field, but you don’t want to. 100% there is a correct way in php/laravel.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question