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.

php - how compare 2 arrays , remove duplicate values

php - merging 2 array 1 array (also remove duplicates)

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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -