How to get second value from array in laravel?

Member

by deron , in category: PHP Frameworks , 6 months ago

How to get second value from array in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by lindsey.homenick , 6 months ago

@deron 

In Laravel, you can access the second value from an array using the array_get function provided by Laravel. Here's how you can do it:

1
2
3
4
5
$array = [1, 2, 3, 4, 5];

$secondValue = array_get($array, 1);

dd($secondValue);


Alternatively, you can also access the second value from the array directly by using array indexing:

1
2
3
4
5
$array = [1, 2, 3, 4, 5];

$secondValue = $array[1];

dd($secondValue);


Both methods will give you the second value (in this case, 2) from the array.