Php combine an array of values into an array with double combinations string -
how can combine ad array of values array double combination string without duplications ?
for example, if have like:
array('one','two','tre','four','five'); i want obtain array of combinations ('one / two') 1 time , not ('two / one').
in way wanto similar to:
array('one/two', 'one/tre', 'one/four', 'one/five', 'two/tree','two/four' ....... suggestions ?
you can code. won't show two/one, three/two, etc (that's how understood it):
<?php $array = array('one','two','tre','four','five'); $newarray = []; foreach ($array $el) { foreach ($array $el2) { if ($el === $el2) continue; $newarray[] = $el."/".$el2; } array_shift($array); // remove element went through } print_r($newarray);
Comments
Post a Comment