| Viewed 14 times

How to returns only the specified pairs from the given array in laravel


How to returns only the specified pairs from the given array in laravel

1 Answer
Mohammad Qandeel
Answered
0

You can use the only() helper function to returns only the specified pairs from the given array in laravel

For Laravel developers when you have a large array and you need to slice a specific element.

If you want to get only the specified pairs from the given array in laravel only() helper function which will return only the specified key-value pairs from the given array

Example of how to use only() helper function

 

use Illuminate\Support\Arr;

$array = ['name' => 'photo', 'price' => 100, 'orders' => 10];

$slice = Arr::only($array, ['name', 'price']);

Output

 ['name' => 'photo', 'price' => 100]

 


Related FAQ