Skip to content
Advertisement

PHP How to extract non serialize array into variables

How can I convert the following array stored in my database into a PHP array, and then extract them into PHP variables:

{"wpversion":"5.4.2","debug_mode":false,"phpversion":"7.3.16","child_version":"4.0.7.1","memory_limit":"768M","mysql_version":"5.6.40-84.0-log","themeactivated":"Child Theme","ip":"0.0.0.0"}

I have been able to use “unserialize()” in other arrays and but this doesn’t seem to work. Also “extract()” only seems to work when it is already in a PHP array not a mySQL array.

Advertisement

Answer

This is a json string to access it as php arrays you must decode it by using json_decode as

$data = '{"wpversion":"5.4.2","debug_mode":false,"phpversion":"7.3.16","child_version":"4.0.7.1","memory_limit":"768M","mysql_version":"5.6.40-84.0-log","themeactivated":"Child Theme","ip":"0.0.0.0"}';
$decode = json_decode($data,true);
print_r($decode);

When TRUE, returned objects will be converted into associative arrays.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement