php - Remove from multidimensional array if value partially matches -


i write multilingual wordpress homepage. need load languages array, detect user language , depending on user language remove other languages array.

i want partial check on array see if "title" contains _de or _es , depending on result remove 1 or other array.

so far have

data

array(2) {  [1]=> array(3) { ["order"]=> string(1) "1" ["title"]=> string(9) "slider_es" ["id"]=> string(3) "500" }   [2]=> array(3) { ["order"]=> string(1) "2" ["title"]=> string(11) "slider_de" ["id"]=> string(3) "493" }   }  

logic

$current_language = get_locale(); // wordpress function returns either es_es or de_de codes  if ($current_language == es-es) {      foreach ($array $key => $item) {         if ($item['title'] === '_de') {             unset($array[$key]);         }     }  } else {      foreach ($array $key => $item) {         if ($item['title'] === '_es') {             unset($array[$key]);         }     }  } 

what did miss?

you can use strpos function used find occurrence of 1 string inside other this:

if (strpos($item['title'],'_de') !== false) {     unset($array[$key]); } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -