Note that there are some explanatory texts on larger screens.

plurals
  1. POmove an array if the corresponding values are at the minimum of 5 iterations has a duplicate
    primarykey
    data
    text
    <p>Is there a php code that can move a multidimensional array minimum of 5 iterations if the values has a duplicate?</p> <p>This is an example code.</p> <pre><code>&lt;?php $results = array( array('value' =&gt; 10), array('value' =&gt; 2), array('value' =&gt; 1), array('value' =&gt; 3), array('value' =&gt; 2), //This will move array('value' =&gt; 4), array('value' =&gt; 5), array('value' =&gt; 5), //This will move array('value' =&gt; 3), //This will move array('value' =&gt; 4), //This will move array('value' =&gt; 10), //Ok reach minimum of 5 count array('value' =&gt; 9), array('value' =&gt; 8), array('value' =&gt; 7), array('value' =&gt; 7), // This will move array('value' =&gt; 8), // This will move array('value' =&gt; 1), //Ok reach minimum of 5 count array('value' =&gt; 6), array('value' =&gt; 6), // This will move array('value' =&gt; 19) //Ok reach minimum of 5 count ); ); ?&gt; </code></pre> <p><br> This is the basic idea. I want to move the values if they found a duplicate within a minimum of 5 iterations. The moving of iterations can move greater than 5. The data can be random. It will loop to find a better result. Is this possible?<br></p> <p>Here is my expected results. This can be other results that can satisfies the logic.<br></p> <pre><code>&lt;?php $results = array( array( array('value' =&gt; 6), //Ok array('value' =&gt; 9), //Ok array('value' =&gt; 2), //Ok array('value' =&gt; 7), //Ok array('value' =&gt; 1), //Ok array('value' =&gt; 4), //Ok array('value' =&gt; 8), //Ok array('value' =&gt; 5), //Ok array('value' =&gt; 9), //Ok array('value' =&gt; 2), //Ok array('value' =&gt; 3), //Ok array('value' =&gt; 6), //Ok array('value' =&gt; 4), //Ok array('value' =&gt; 10), //Ok array('value' =&gt; 8), //Ok array('value' =&gt; 7), //Ok array('value' =&gt; 1), //Ok array('value' =&gt; 3), //Ok array('value' =&gt; 5), //Ok array('value' =&gt; 10) //Ok ); ); ?&gt; </code></pre> <p><br></p> <p>Hope you can help me.</p> <p><strong>EDIT:</strong></p> <p>Here is my code</p> <pre><code>&lt;?php $required_array = array(); $temp = ""; $temp2 = ""; foreach($array as $key=&gt;$child) { if( $child["value"]==$temp ) { $i = $key+5; $required_array[$i] = $child; } else { $i = $key; //if(isset($required_array[$i])) $i++; while(isset($required_array[$i])) { $i++; } $required_array[$i] = $child; } $temp = $child["value"]; } ksort($required_array); print_r($required_array); //Tried this but always move on five iterations and found duplicate within the range of five </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload