<?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) use ($filter){
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);
$o = '';
if(!empty($cVis)){
$cVisStr = 'columnDefs: [ { targets: [ ';
$cVisInd = [];
for ($i = 0; $i < $vars['cNum']; $i++){
if(array_key_exists('cVis_' . $i, $cVis)){
$cVisInd[] = (int) $i;
}
}
$o = $cVisStr .= implode(',',$cVisInd) .'], visible: false} ]';
$jsout[] = $cVisStr;
}
var_dump($o);
preferences:
38.74 ms | 402 KiB | 5 Q