Split array into unique pairs

前端 未结 6 1368
感动是毒
感动是毒 2021-01-06 02:05

Say i start with a simple array (which could be theoretically of any length):

$ids  = array(1,2,3,4);

What it the best solution for splitti

6条回答
  •  囚心锁ツ
    2021-01-06 02:55

    $ids  = array(1,2,3,4);
    $result=array();
    foreach($ids as $value_1)
    {
      foreach($ids as $value_2)
      {
         if($value_1 !=$value_2)
         {
           $result[]=array($value_1,$value_2);
         }
       }
    }
    echo "
    ";
    print_r($result);
    

提交回复
热议问题