Support the ongoing development of Laravel.io →
posted 10 years ago
Session
Last updated 2 years ago.
0
Solution

This works, I guess...

$key = 'UserChoices';

Session::put($key, [10,22,31]);	/* Lets start with some data */

$choices   = Session::get($key); /* Get all ids. returns (array) */

$idExists  = in_array($choices, $id); /* Id exists ?  returns (bool) */

$choices[] = $idToAdd;	/* Add a single id */

$choices = array_merge($choices, $arrayOfIds);	/* Ad an array of ids */

unset( $choices[$idToRemove] );	/* Remove an id */

Session::put($key, $choices); /* Just save it ! */
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.