Jump to content

AhmadAli90

New Members
  • Posts

    2
  • Joined

  • Last visited

AhmadAli90's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you Sir, this works fine but there's only one issue, i need it to select 5-10 boxes from the whole grid, not for each and every 4*4 box, how can i do that?
  2. Hello, how can i randomly select 5-10 boxes and color those selected differently from this entire grid? code done so far: <!DOCTYPE HTML> <html> <head> <title>Arrays -1- </title> <style> table { width: 200px; height:200px margin: 15px; border-collapse: collapse; border: 2px solid black; } tr,td{ height: 50px; } td{ border: 1px solid gray; width: 100px; vertical-align: middle; text-align: center; } .paint{ z-index:3; background-color: pink; } </style> </head> <body> <?php ini_set('max_execution_time', 0); $quest = array ( "TL" => array ( array(2,2,2,2), array ( 2,2,2,2), array ( 2,2,2,2) , array ( 2,2,2,2) ) , "TR" => array ( array(2,2,2,2), array ( 2,2,2,2), array ( 2,2,2,2) , array ( 2,2,2,2) ) , "BL" => array (array(2,2,2,2), array ( 2,2,2,2), array ( 2,2,2,2) , array ( 2,2,2,2) ) , "BR" => array (array(2,2,2,2), array ( 2,2,2,2), array ( 2,2,2,2) , array ( 2,2,2,2) ) ); echo "<table>"; $con = 1; /*$ccounter=0; do{ foreach($quest as $keyOut=>&$dataOut){ foreach($dataOut as $keyMid=>&$dataMid){ foreach($dataMid as $key=>&$data){ $color = rand(1,2); if($color == 1) $ccounter++; $data=$color; } } } }while(!($ccounter>=5&&$ccounter<=10)); */ $count=0; foreach($quest as $keyOut=>&$dataOut){ if($con==1){ echo "<tr> <td>"; }else{ echo "<td>"; } echo "<table>"; foreach($dataOut as $keyMid=>&$dataMid){ echo "<tr>"; foreach($dataMid as $key=>&$data){ if($data==2) //if($clr==2) echo "<td>$data</td>"; else {echo "<td class=\"paint\">$data</td>"; } } echo "</tr>"; } echo "</table>"; if($con ==1){ echo "</td>"; $con = 2; }else{ echo "</td> </tr>"; $con = 1; } } echo "</table>"; $tl=$quest["TL"]; echo "<table>"; foreach($tl as $keyO=>$dataO){ echo "<tr>"; foreach($dataO as $keyM=>$dataM){ if($dataM==2) //if($clr==2) echo "<td></td>"; else {echo "<td class=\"paint\"></td>"; } } echo "</tr>"; } ?> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.