PHP: Search SubString in Array -


this question has answer here:

i want array index particular substring.

here got far:

<?php     $array = array(0 => 'blau', 1 => 'rot', 2 => 'grün', 3 => 'rot');     $key = array_search('grün', $array);  // $key = 2;     $key = array_search('rot', $array);   // $key = 1; ?> 

it matches whole value. but, want match substring. there predefined function achieve goal?

you try use array_filter strpos

function search($var) {     if(strpos($var, 'some_sub_string') !== false){         return true;     }      return false; }  $array = array(0 => 'blau', 1 => 'rot', 2 => 'grün', 3 => 'rot'); array_filter($array, 'search')); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -