If you want to add these array to a session value where you had already entered a given one, the best way would be to use the method 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 the array
directly on key
specific:
session()->put('session_array', $array)
You can also access define values through point notation:
session('session_array.nome', 'Wallace');
session('session_array.1', 10);
session('session_array.2', 20);
Alternatively you can also define a array
directly:
session(['session_array' => [1, 2, 3, 4, 5]);
To get the values, you can do the following ways:
//equivale a $_SESSION['session_array']['name']
session('session_array.name');
session('session_array.1');
session('session_array.name')
is returning the whole array.– Kelvym Miranda
In that case, you must have defined the
array
in it all.– Wallace Maxters
He is returning:
Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1)
– Kelvym Miranda