3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 'a', 'b', 'c' => array(1,2) ); $formt = array( 'A' => array( 'is_need' => true, 'type_condition' => 'or', 'type' => false, ), 'B', 'C' => array( 'child' => array( 'C1' => array( 'is_need' => true, 'type_condition' => 'or', 'type' => false, ), 'C2' => array( 'is_need' => true, 'type_condition' => 'or', 'type' => false, ), ) ), ); function formatParams($arr, $formt) { list($f_k, $f_v) = each($formt); $data = array(); foreach($arr as $key => $val) { if(is_array($val)) { $data[$f_k] = formatParams($val, $f_v['child']); } else { if(is_array($f_v)) { $data[$f_k] = $val; } else { $data[$f_v] = $val; } } list($f_k, $f_v) = each($formt); } return $data; } // var_dump(formatParams($arr, $formt)); list($key, $val) = each($arr); for($i = 0; $i <= 4;++$i) { echo $key . "\n"; echo (list($key, $val) = each($arr)) . "\n"; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Uncaught Error: Call to undefined function each() in /in/HM1AV:46 Stack trace: #0 {main} thrown in /in/HM1AV on line 46
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /in/HM1AV on line 46 0 Notice: Array to string conversion in /in/HM1AV on line 49 Array 1 Notice: Array to string conversion in /in/HM1AV on line 49 Array c
Output for 7.3.32 - 7.3.33
0 Array 1 Array c
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20
0 Notice: Array to string conversion in /in/HM1AV on line 49 Array 1 Notice: Array to string conversion in /in/HM1AV on line 49 Array c

preferences:
156.13 ms | 402 KiB | 179 Q