1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?php
$tab = array('titi','toto tata','tutu','toto','azetototy','tata','tatayoyo','tata yoyototo','titi tutu tata');
function test_alter(&$item, $key, $prefix)
{
$prefix = array_map('trim',$prefix);
foreach ($prefix as $value)
{
$prefix_ = str_replace(' ', '_', $value);
$item_ = str_replace($value, $prefix_, $item);
$tab_mots = explode(' ',$item_);
if(in_array($prefix_,$tab_mots)) $item = null;
}
}
$sup = array('titi tutu','titi','tata yoyo','toto');
array_walk($tab, 'test_alter', $sup);
$tab = array_filter($tab);//supprime les éléments null ou vide ou false
$tab = array_merge($tab);// en option si besoin pour réindexer le tableau
echo '<pre>';
print_r($tab);
echo '</pre>';
?> |
Partager