3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('FILTER_STRUCT_FORCE_ARRAY', "\0FILTER_STRUCT_FORCE_ARRAY\0"); function filter_struct_utf8($type, array $default) { static $is_recursive_static = false; $is_recursive = $is_recursive_static; if (!$is_recursive) { $types = array( INPUT_GET => $_GET, INPUT_POST => $_POST, INPUT_COOKIE => $_COOKIE, INPUT_REQUEST => $_REQUEST, INPUT_ENV => $_ENV, INPUT_SERVER => $_SERVER, ); $type = (int)$type; if (!isset($types[$type])) { return $default; } $var = $types[$type]; $is_recursive_static = true; } else { $var = $type; } $ret = array(); foreach ($default as $key => $value) { if ($value === FILTER_STRUCT_FORCE_ARRAY) { $ret[$key] = array(); $arr = isset($var[$key]) ? (array)$var[$key] : array(); foreach ($arr as $k => $v) { if (is_string($v) && preg_match('//u', $k) && preg_match('//u', $v)) { $ret[$key][$k] = $v; } } } elseif (!isset($var[$key])) { $ret[$key] = $value; } elseif (is_array($value)) { $ret[$key] = filter_struct_utf8($var[$key], $value); } elseif (is_array($var[$key]) || !preg_match('//u', $var[$key])) { $ret[$key] = $value; } else { $ret[$key] = $var[$key]; } } if (!$is_recursive) { $is_recursive_static = false; } return $ret; } // テスト用として代入($_POST['email']は未定義) $_POST['name'] = array( // 異常な値(本来は文字列で来るはず) 'hahaha' => 'I am an array', ); $_POST['age'] = '20'; // 正常な値 $_POST['gender'] = 'male'; // 正常な値 $_POST['options] = array( 'b' => 'yes', // 正常な値 'c' => array('hahaha' => 'This is an invalid option'), // 異常な値(本来は配列はネストしないはず) ); // $_POSTの要素を期待する形になるようにシンボルテーブルにインポートする extract(filter_struct_utf8(INPUT_POST, array( 'name' => '', // 異常なときは強制的に空文字列にする 'age' => '', // 異常なときは強制的に空文字列にする 'email' => '', // 異常なときは強制的に空文字列にする 'gender' => '', // 異常なときは強制的に空文字列にする 'options' => FILTER_STRUCT_FORCE_ARRAY, // 強制的に一次元配列にする ))); // 値を見てみる var_dump($name, $age, $email, $gender, $options);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.200.0050.03812.42
5.4.190.0170.04412.41
5.4.180.0200.04712.41
5.4.170.0170.04812.42
5.4.160.0210.04612.41
5.4.150.0200.04312.41
5.4.140.0180.04212.10
5.4.130.0120.04612.08
5.4.120.0140.04412.05
5.4.110.0110.04612.04
5.4.100.0130.04712.04
5.4.90.0110.04712.04
5.4.80.0160.04212.04
5.4.70.0110.04612.04
5.4.60.0160.04212.04
5.4.50.0200.03812.04
5.4.40.0150.04312.02
5.4.30.0160.04212.02
5.4.20.0140.04312.02
5.4.10.0220.03612.02
5.4.00.0230.06211.51
5.3.270.0140.04912.73
5.3.260.0180.04712.72
5.3.250.0130.04812.72
5.3.240.0150.04912.72
5.3.230.0190.04412.71
5.3.220.0210.04112.68
5.3.210.0150.04612.68
5.3.200.0170.04812.68
5.3.190.0210.04312.68
5.3.180.0190.04312.67
5.3.170.0230.04112.67
5.3.160.0200.04412.68
5.3.150.0170.04612.67
5.3.140.0160.04812.66
5.3.130.0190.04412.66
5.3.120.0170.05112.66
5.3.110.0200.05112.66
5.3.100.0180.04412.14
5.3.90.0150.04912.12
5.3.80.0150.04812.11
5.3.70.0320.09012.11
5.3.60.0210.04212.09
5.3.50.0210.04312.04
5.3.40.0180.04212.04
5.3.30.0180.04412.01
5.3.20.0150.04511.79
5.3.10.0190.03811.75
5.3.00.0180.04211.73

preferences:
132.29 ms | 1394 KiB | 7 Q