arrays - filter away duplicates in two lists not containing a dot php -
say have 2 arrays
array a
n1099 n1100 n1100.1 n1100.2 n1100.3 n1100.4 n1100.5 n1101 n1101.1
array b
n1100.1 n1100.2 n1100.3 n1100.4 n1100.5 n1100.6 n1101.1
now can see array contains n1100 , n1101 , has "children" in list b. want remove parent in array becomes:
resulting array after comparing 2 arrays
n1099 n1100.1 n1100.2 n1100.3 n1100.4 n1100.5 n1101.1
how can done in php?
i found questions merge 2 arrays , filter duplicates , thats not case here. want filter away duplicates not containing dot "." in it.
you need in following manner:-
<?php $lista = array('n1099','n1100','n1100.1','n1100.2','n1100.3','n1100.4','n1100.5','n1101','n1101.1'); $listb = array('n1100.1','n1100.2','n1100.3','n1100.4','n1100.5','n1100.6','n1101.1'); $listc = array(); $lista = array_unique($lista); foreach($lista $lisa){ if(in_array($lisa,$listb) || !in_array($lisa.'.1',$listb)){ $listc[] = $lisa; } } echo"<pre/>";print_r($listc); ?>
output:-https://eval.in/379229
Comments
Post a Comment