| Viewed 21 times

How to returns and removes a key-value pair from an array in laravel


How to returns and removes a key-value pair from an array in laravel

1 Answer
Mohammad Qandeel
Answered
0

You can use the pull() helper function to get and removes a key-value pair from an array in laravel

For Laravel developers, you can get the key-value pair from an array and remove it from the original array 

If you want to returns and removes a key-value pair from an array in laravel pull() helper function which will return a string.

you can also set a default value if the key doesn't exist. $value = Arr::pull($array, $key, $default);

Example of how to use pull() helper function

use Illuminate\Support\Arr;

$array = ['name' => 'Desk', 'price' => 100];

$name = Arr::pull($array, 'name');

Output

// $name: Desk

 

$array
=> [
     "price" => 100,
   ]



Related FAQ