I am storing an array in string form in a database for later retrieval: The value of the array happens to be parameters for a filter_val call.
$str = 'array("options" => array("min_range" => 4))';
I know I can use
eval('$options = ' . $str . ';');
to prepare this value for passing to filter_val, but is there any other way to do this?
This related post (while excellent) didn't handle my exact issue.
I would not use eval()
to get your string functional. For example, the function eval
may be disallowed on some hosts, thus your application will not work.
A more appropriate way would be to store your options in a json_encode()
'd string, and decode when you need.
$options = json_decode($options_from_db);