All,
I’ve created a whole bunch of session variables based on an id. So for example I can have the following variables:
$_SESSION['test_variable_1'];
$_SESSION['test_variable_2'];
$_SESSION['test_variable_3'];
I’d like to read all of these with PHP and basically return a JSON array of the id at the end of the variable. So I’d like 1, 2 and 3 returned in this example. The session variables I wnat to look at will always start with test_variable_ and followed by the ID I want to obtain. What is the best way to do this?
Thanks!
While the better idea would’ve been to just create a sub-array within the session superglobal, so that you could use
$_SESSION['test_variable'][1]and the like, you can use something like preg_grep to scan for these keys: