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]); }