数组不区分大小写添加到它删除空格,strtolower不足以在这种情况下正常工作

Is it possible to do case-insensitive following by removing spaces when do search in an array

So with a source array like this:

$a= array(
 'Especificação do instrumento :',
 'especificação do instrumento : ',
 'Especificação do Instrumento :',
 'Especificação do Instrumento : '

);

The following lookups would all return true:

in_array('Especificação do instrumento :', $a);
in_array('especificação do instrumento : ', $a);
in_array('Especificação do Instrumento :', $a);
in_array('Especificação do Instrumento : ', $a);

What function or set of functions would do the same? I don't think in_array with strtolower can do this.

Use this answer Case-insensitive array search and add trim to the value and each array element:

array_search(trim(strtolower($search)), array_map(function($v) {
                                                      return trim(strtolower($v));
                                                  }, $array));

This handles spaces at the beginning and end. To handle multiples in the middle you would need to preg_replace multiple spaces with one.

used:

$key = array_search(strtolower(preg_replace('/\s+/', '', "Especificação do instrumento :")), array_map('strtolower', preg_replace('/\s+/', '', $array)));