3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ruleTypes() { $ruleArray = []; $types = [0 => ['type' => 'required', 'value_1' => null, 'value_2'=> null], ['type' => 'min', 'value_1' => 3, 'value_2'=> 0, 'value_2'=> null], ['type' => 'max', 'value_1' => 10, 'value_2'=> null], ['type' => 'between', 'value_1' => 10, 'value_2'=> 100] ]; $arr = []; foreach ($types as $type) { if (\in_array($type['type'], getNoValidationValueRequired())){ $ruleArray[] = $type['type']; }else { $ruleArray[] = sortRulesOrder($type); // $value . ':' . $value } } return implode('|', $ruleArray); } function sortRulesOrder(array $type) { $type = null; if(!empty($type['type'])) { if($type['value_1'] && $type['value_2']) { return $type['type'] . ':' . $type['value_1'] .',' .$type['value_2']; } else { $value = $type['value_1'] ? $type['value_1'] : $type['value_2']; return $type['type'] . ':' . $value; } } } $type['value_1'] ? $type['value_1'] : $type['value_2'] === $type['value_1'] ?: $type['value_2']; function getNoValidationValueRequired() { return ['required']; } var_dump(ruleTypes());
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Fatal error: Unparenthesized `a ? b : c ?: d` is not supported. Use either `(a ? b : c) ?: d` or `a ? b : (c ?: d)` in /in/dtrkZ on line 38
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Unparenthesized `a ? b : c ?: d` is not supported. Use either `(a ? b : c) ?: d` or `a ? b : (c ?: d)` in /in/dtrkZ on line 38
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: Unparenthesized `a ? b : c ?: d` is deprecated. Use either `(a ? b : c) ?: d` or `a ? b : (c ?: d)` in /in/dtrkZ on line 38 Notice: Undefined variable: type in /in/dtrkZ on line 38 Notice: Trying to access array offset on value of type null in /in/dtrkZ on line 38 Notice: Undefined variable: type in /in/dtrkZ on line 38 Notice: Trying to access array offset on value of type null in /in/dtrkZ on line 38 Notice: Undefined variable: type in /in/dtrkZ on line 38 Notice: Trying to access array offset on value of type null in /in/dtrkZ on line 38 string(11) "required|||"
Output for 7.3.32 - 7.3.33
string(11) "required|||"
Output for 7.1.0 - 7.1.21, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31
Notice: Undefined variable: type in /in/dtrkZ on line 38 Notice: Undefined variable: type in /in/dtrkZ on line 38 Notice: Undefined variable: type in /in/dtrkZ on line 38 string(11) "required|||"

preferences:
150.72 ms | 402 KiB | 169 Q