如何从多维数组中仅获取数组值

I am doing project in laravel. I am fetching a value from database in user1 variable.

foreach($users1 as $us){
                    $uss[$i] = $us->city_id;
                    $users2[$i] = DB::table('provider_city')->select('provider_id')->where('city_id','=', $uss[$i])->get();
                    $i++;
                }
return $users2;

when I return user2, I am getting [[{"provider_id":"14785"}],[{"provider_id":"125478"}]] such values.

I want only values like ['14785','125478'].

I know this may be very simple. Give suggestions.

This can be achieved with json_decode, like so

$json= '[
    {
      "provider_id": "14785"
    },
    { 
      "provider_id": "125478"
    }
  ]';

$jsonDecoded = json_decode($json);
foreach($jsonDecoded as $item)
{
    //Do something with it, e.g
    echo $item->provider_id;
}

Edit: Upon finding out that this is a multidimensional array

This question here should point you in the right direction.

There's actually an Eloquent method for that - lists():

$users2[$i] = DB::table('provider_city')
    ->where('city_id','=', $uss[$i])
    ->lists('provider_id')
    ->all();

This will give you an array of just the provider ids.

Whether you need the all() call at the end or not depends essentially on what version of Laravel you're using.

Maybe something like

return DB::table('provider_city')
    ->whereIn('city_id', array_pluck($users1, 'city_id')
    ->lists('provider_id');