I have some data in this format:
even--heaped<br /> even--trees<br /> hardrocks-cocked<br /> pebble-temple<br /> heaped-feast<br /> trees-feast<br />
and I want to get the result so that all lines with the same words are not added to each other without repetition.
even--heaped--trees--feast<br /> hardrocks--cocked<br /> pebbles-temple<br />
I tried a loop going through both arrays, but this is not the exact result I want. for the $ thing array:
Array ( [0] => even--heaped [1] => even--trees [2] => hardrocks--cocked [3] => pebbles--temple [4] => heaped--feast [5] => trees--feast ) for ($i=0;$i<count($thing);$i++){ for ($j=$i+1;$j<count($thing);$j++){ $first = explode("--",$thing[$i]); $second = explode("--",$thing[$j]); $merge = array_merge($first,$second); $unique = array_unique($merge); if (count($unique)==3){ $fix = implode("--",$unique); $out[$i] = $thing[$i]."--".$thing[$j]; } } } print_r($out);
but the result:
Array ( [0] => even--heaped--heaped--feast [1] => even--trees--trees--feast [4] => heaped--feast--trees--feast )
what I do not want. Any suggestions (sorry for the awful variable names ).
source share