3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $vars = ['len' => '-1', 'start' => '0', 'cNum' => '7', 'cSearch_0' => 'b', 'cSearch_1' => 'c', 'cSearch_2' => 'd', 'cSearch_3' => 'e', 'cSearch_4' => 'f', 'cSearch_5' => 'g', 'cSearch_6' => 'h', 'cSort_0' => 'asc', 'cSort_1' => 'asc', 'search' => 'a']; function _filterArrayByKey(string $filter, $array){ return array_filter( $array, function($k){ return preg_match('/(' . $filter . ')/',$k); }, ARRAY_FILTER_USE_KEY ); } // $v = preg_grep('/[cSearch]\_/', array_keys($vars)); // $cSearch = array_filter($vars, function($k){ return preg_match('/(cSearch)/',$k);}, ARRAY_FILTER_USE_KEY); $cVis = _filterArrayByKey('cVis',$vars); var_dump($cVis); if(!empty($cVis)){ $cVisStr = 'columnDefs: [ { targets: [ '; $cVisInd = []; for ($i = 0; $i < $vars['cNum']; $i++){ if(array_key_exists('cVis_' . $i, $cVis)){ $cVisInd[] = (int) $i; } } $cVisStr .= implode(',',$cVisInd) .'], visible: false} ]'; $jsout[] = $cVisStr; } var_dump($cVisStr);
Output for 7.3.0rc3
Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 Notice: Undefined variable: filter in /in/4uLRS on line 21 array(13) { ["len"]=> string(2) "-1" ["start"]=> string(1) "0" ["cNum"]=> string(1) "7" ["cSearch_0"]=> string(1) "b" ["cSearch_1"]=> string(1) "c" ["cSearch_2"]=> string(1) "d" ["cSearch_3"]=> string(1) "e" ["cSearch_4"]=> string(1) "f" ["cSearch_5"]=> string(1) "g" ["cSearch_6"]=> string(1) "h" ["cSort_0"]=> string(3) "asc" ["cSort_1"]=> string(3) "asc" ["search"]=> string(1) "a" } string(47) "columnDefs: [ { targets: [ ], visible: false} ]"