3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fileData = '$orange="100kg";$Apple="400kg";$Peach="543kg";'; $patternVars = '/(?<=\$).*?(?=\=)/m'; $patternValues = '/(?<="(?!;)).*?(?=")/m'; $vars = preg_match_all($patternVars, $fileData, $varMatches); // Match all variables $values = preg_match_all($patternValues, $fileData, $valueMatches); // Match all values forEach($varMatches[0] as $key => $value){ // Use the value to name your variable (hence the weird looking "$$") and set the value of this variable to the matches of your values. $$value = $valueMatches[0][$key]; } var_dump($orange); // Will output "100kg"

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
175.68 ms | 1867 KiB | 10 Q