3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function ksortMultiDimensional(&$params = array()) { if (is_array($params)) { ksort($params); foreach ($params as &$p) { if (is_array($p)) { ksort($p); } } } } function process($params, $key, $version = 2) { ksortMultiDimensional($params); $baseString = prepareParams($params, $baseString); $baseString .= $key; if ($version == self::VERSION_TWO) { return md5($baseString); } return hash('sha256', $baseString); } function prepareParams($params = array(), $baseString = '') { foreach ($params as $key => $value) { if (!isset($value)) { continue; } if (is_array($value)) { foreach ($value as $k => $v) { $baseString .= $key . '[' . $k . ']' . '=' . ($v === false ? '0' : $v); } } else { $baseString .= $key . '=' . ($value === false ? '0' : $value); } } return $baseString; } $data = [ 'key1' => 'Hello', 'key2' => 2, 'key3' => [ 'key4' => 'hello', 'key5' => 'world', 'abc' => 'def', ], 'key0' => 'yolo', 'key11' => null, 'key111' => 1.2 ]; var_dump(process($data, 'abc', 3));
based on 7sWLi
Output for 7.0.0 - 7.1.7
Fatal error: Cannot use "self" when no class scope is active in /in/vCUqN on line 20
Process exited with code 255.
Output for hhvm-3.15.4
Notice: Undefined variable: baseString in /in/vCUqN on line 18 Fatal error: Uncaught Error: Cannot access self:: when no class scope is active in /in/vCUqN:20 Stack trace: #0 /in/vCUqN(56): process() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Notice: Undefined variable: baseString in /in/vCUqN on line 18 Fatal error: Cannot access self:: when no class scope is active in /in/vCUqN on line 20
Process exited with code 255.