Jump to content

Solence

New Members
  • Posts

    3
  • Joined

  • Last visited

Solence's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Alright i actually managed to fix my problem. Thx for yout time
  2. in the first table im generating a random number with each loop which i then put into an array for the second table. So the array is already done. I have no idea how i output an array into a table. At least not the way i want. I only manage to get ether a table with the full array in each field or the same single value of the array in each field. Right now i tried to play around with foreach ($array as &$value); but this just shows me the same number in each field again. I only started a few days ago with php so i barely understand my own code.
  3. <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="stylesheet.css"> <meta charset="utf-8"> </head> <body> <?php $array = array(); echo "<table>"; for ($z=0; $z <=9; $z++) { echo "<tr>"; for ($s=0; $s <=9; $s++) { $r = mt_rand (1, 100); array_push ($array, $r); if ($r %2 != 0) { echo "<td bgcolor = red>"; echo $r; echo "</td>"; } else { echo "<td bgcolor= lightgreen>"; echo $r; echo "</td>"; } } echo "</tr>"; } echo "</table>"; echo "<br>"; echo "<table>"; sort($array); $arraysplit = array_chunk($array, count($array)/10); for ($z=0; $z <=9; $z++) { echo "<tr>"; for ($s=0; $s <=9; $s++) { if ($r %2 != 0) { echo "<td bgcolor = red>"; echo json_encode (arraysplit); echo "</td>"; } else { echo "<td bgcolor= lightgreen>"; echo json_encode ($arraysplit); echo "</td>"; } } echo "</tr>"; } ?> </body> </html> Hey absolute beginner here. Im working on a table that gives random numbers out and then colorizes them if they can be devided by 2. That works fine. Now i want to get those randomly generated numbers into a second table but sorted. I already managed to put the numbers i generated into an array and sort it but i cant figure out how to echo them 1 by 1 into the table. Maybe you can help me out.
×
×
  • 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.