3v4l.org

run code in 300+ PHP versions simultaneously
<?php function buildVirtualData($var) { if ( is_string($var) && null !== $json = json_decode($var, true) ) $var = $json; if ( is_array($var) ) return array_map('buildVirtualData', $var); return $var; } $_POST = array( "valor1" => 1200, "valor2" => "texto", "valor3" => true, "valor4" => '{"seclvl_text":"datp","seclvl_boolean":"false", "nestedJSONString":"{\"key\":\"value\"}"}', "valor5" => "true" ); var_dump(buildVirtualData($_POST));
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.23, 7.4.0 - 7.4.11, 8.0.0alpha1 - rc2
array(5) { ["valor1"]=> int(1200) ["valor2"]=> string(5) "texto" ["valor3"]=> bool(true) ["valor4"]=> array(3) { ["seclvl_text"]=> string(4) "datp" ["seclvl_boolean"]=> bool(false) ["nestedJSONString"]=> array(1) { ["key"]=> string(5) "value" } } ["valor5"]=> bool(true) }