3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 7.2.0
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 5.4.10 - 7.1.10
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 5.3.20 - 5.3.29
0 Array 1 Array c