Good day. The database has a params field in which arbitrary keys and values are placed in the format: key => value, key2 => value2, ..., etc.
After receiving the params field in the $ params variable, I take the parameters as follows:
eval('$array=array(' . $params . ');'); extract($array); In other words: there is a string variable:
$params = "key=>value, key2=>value2, key3=>value3"; //это не массив, это просто строка We need an algorithm for obtaining from this line the usual associative array.
Than eval is cool because it correctly converts even such a string to an array:
$params = 'key=>"Lorem, ipsum; 22", key2=>[value2, value3, value4], key3=>value3'; Does this “algorithm” work, but am I confused by eval? Is my decision right? Is there a more elegant and correct way?
k=>vthrough explode by the symbol=>..... and collect the array .... and then this array already makeextract...... becauseevalis dangerous and it is necessary to use it when there is no other choice at all - Alexey Shimansky