move an array if the corresponding values are at the minimum of 5 iterations has a duplicate

后端 未结 1 1784
不思量自难忘°
不思量自难忘° 2021-01-20 17:24

Is there a php code that can move a multidimensional array minimum of 5 iterations if the values has a duplicate?

This is an example code.



        
相关标签:
1条回答
  • 2021-01-20 18:01

    array_chunk solve my issue.

    <?php
    $chunks = array_chunk($array, ceil(count($array)/5));
    $array = array();
    
    for($x = 0, $numX =  count($chunks[0]); $x < $numX; $x++){
        for($y = 0, $numY = count($chunks); $y < $numY; $y++){
            if(isset($chunks[$y][$x]))
            //echo $x.' '.$y.'<br>';
            $array[] = $chunks[$y][$x];
        }
    }
    print_r($array);
    ?><br>
    

    Anyway, my next problem is if I have two rows in an array. Like the example below.

    <?php
    $array   =  array(
                     array('value' => 1, 'value2' => 2),
                     array('value' => 3, 'value2' => 1)
                     );
    
    ?><br>
    

    How can I check both sides (value and value2) for duplicates and used my existing code?

    0 讨论(0)
提交回复
热议问题