jojacafe
8/11/2017 - 6:44 AM

Search in array similar like mysql and get elements, without case sensitive

Search in array similar like mysql and get elements, without case sensitive

$data = [
  [ 'Country' => 'Chinas', 'Out_Count' => 14 ],
  [ 'Country' => 'Belgium', 'Out_Count' => 2 ],
  [ 'Country' => 'China', 'Out_Count' => 33 ],
  [ 'Country' => 'France', 'Out_Count' => 7 ]
];

$result = array_keys(preg_grep('~CHINA~i', array_column($data, 'Country')));

$newArray = [];
foreach($result as $i) {
    $newArray[] = $data[$i];
}

var_dump($newArray);