I am trying to create an array using the laravel collection function called mapWithKeys , but I could not achieve what I needed.
Here is my code
$years = range(1900, date('Y')); return collect($years)->mapWithKeys(function($value){ return [$value => $value]; })->all();
Expected Result
Array ( [1900] => 1900 [1901] => 1901 [1902] => 1902 .... [2017] => 2017 )
But I get
Array ( [0] => 1900 [1] => 1901 [2] => 1902 ... [117] => 2017 )
source share