Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do not understand the purpose of this, but maybe something like this?</p> <p>Instead of using $row1, $row2, $row3 etc I did these an array. Array is more flexibile to use in this situation. I did an example of how you could input your current variables into one array.</p> <p>I've changed the code and I'm now using a diffrent approach. I use an object to store the array, and after that I use the stored array in the object to "reset" at each iteration of the loop. (OOP is the best way to do things anyway :-)) </p> <pre><code>&lt;?php //Create a class to handle array class arrayHandler { private $row = array(); public function __construct(Array $row) { $this-&gt;row = $row; //Put array into object member } public function loopArray($num=7, $numRandomEntries=3) { for ($nr = 0;$nr&lt;intval($num);$nr++) { //Do seven loops //Get array stored in object $row = $this-&gt;row; //Get three random keys from the $row-array $randomEntries = array_rand($row, intval($numRandomEntries)); //Set random entries elements to value 0 foreach($randomEntries as $key) { $row[$key] = array_fill_keys(range('a', 'f'), 0); } $nNr = $nr+1; echo "row$nNr = " . print_r($row,true)."&lt;hr /&gt;"; //For testing } } } //Your variables with stored arrays... $row1 = array('a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3, 'd' =&gt; 4, 'e' =&gt; 5, 'f' =&gt; 6); $row2 = array('a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3, 'd' =&gt; 4, 'e' =&gt; 5, 'f' =&gt; 6); $row3 = array('a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3, 'd' =&gt; 4, 'e' =&gt; 5, 'f' =&gt; 6); $row4 = array('a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3, 'd' =&gt; 4, 'e' =&gt; 5, 'f' =&gt; 6); $row5 = array('a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3, 'd' =&gt; 4, 'e' =&gt; 5, 'f' =&gt; 6); $row6 = array('a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3, 'd' =&gt; 4, 'e' =&gt; 5, 'f' =&gt; 6); //Create ONE array from each variable above $row = array(); $row[0] = $row1; $row[1] = $row2; $row[2] = $row3; $row[3] = $row4; $row[4] = $row5; $row[5] = $row6; //Create the object and do the looping $ah = new arrayHandler($row); $ah-&gt;loopArray(); ?&gt; </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.
    1. This table or related slice is empty.
    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