If you want to add these array to a session value where you already entered the given agum, the best way would be to use the push
session()->put('session_array', 1);
session->push('session_array', 2);
session->push('session_array', 2);
var_dump(session('session_array')); // [1, 2, 3]
You can also set array
directly to specific key
:
session()->put('session_array', $array)
You can also access define values by dot notation:
session('session_array.nome', 'Wallace');
session('session_array.1', 10);
session('session_array.2', 20);
Alternatively you can also set a array
directly:
session(['session_array' => [1, 2, 3, 4, 5]);
To get the values, you can do the following:
//equivale a $_SESSION['session_array']['name']
session('session_array.name');
session('session_array.1');