Jragon Posted July 20, 2010 Share Posted July 20, 2010 <html> <head> <title>Hats</title> </head> <body> <?php /* Rules: 1 hat must be worn all day A hat must be worn every weekday Cant change hat once put on in the moring Mathmatical Statment 4*4*4*4*4 = 1024 What is going to happen: Every statment will be echoed out E.G: <table> <tr> <th>Monday</th> <th>Tuseday</th> <th>Wesnesday</th> <th>Thesday</th> <th>Friday</th> </tr><tr> <td>Pink</td> <td>Brown</td> <td>Blue</td> <td>Red</td> <td>Red</td> </tr> </table> */ $hat1 = 'Pink'; $hat2 = 'Brown'; $hat3 = 'Blue'; $hat4 = 'Red'; $odd = true; while ($num <= 1024){ } ?> </body> </html> If you reed the notes it says what i want to do If anyone has any ideas how i can do this it would be cool Thanks Jragon Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/ Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 If you reed the notes it says what i want to do No it doesn't or it does in a very cryptic way. Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088626 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 It says what i want to happen Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088627 Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 The point is it doesn't say how the variables you have are related to do output you want. The simplest way is just to echo what you want. echo "<table> <tr> <th>Monday</th> <th>Tuseday</th> <th>Wesnesday</th> <th>Thesday</th> <th>Friday</th> </tr><tr> <td>Pink</td> <td>Brown</td> <td>Blue</td> <td>Red</td> <td>Red</td> </tr> </table>"; but I suspect it's not what you're after is it? Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088641 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 No. Because I'm lasy and dont want to make a table my self for each differnt time. I want php to do it for me using somthing like a while loop or a for loop in the end it would make somthing like this: <table> <tr> <th>Monday</th> <th>Tuseday</th> <th>Wesnesday</th> <th>Thesday</th> <th>Friday</th> </tr><tr> <td>Pink</td> <td>Brown</td> <td>Blue</td> <td>Red</td> <td>Red</td> </tr><tr> <td>pink</td> <td>pink</td> <td>pink</td> <td>pink</td> <td>pink</td> </tr> <tr> <td>blue</td> <td>blue</td> <td>blue</td> <td>blue</td> <td>blue</td> </table> ect. But i have no idea how to do this Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088644 Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 Well I have no idea what you want. Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088652 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 It is going to make a table with a differnt color hat worn every day. Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088654 Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 You mean permutations? Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088655 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 sort ov. the first paragraph is almost correct eddited verstion: In mathematics, the notion of permutation is used with several slightly different meanings, all related to the act of permuting (rearranging in an ordered fashion) objects or values. Informally, a permutation of a set of values is an arrangement of those values into a particular order. Thus there are six permutations of the set {1,2,3}, namely [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1], [3,3,3], [2,2,2], [1,1,1], [3,3,2], [3,2,3] ECT. Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088659 Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 Permutations with repetitions then. The crude way looks like this. $hats = array('pink','brown','blue','red'); foreach($hats as $hat1) { foreach($hats as $hat2) { foreach($hats as $hat3) { foreach($hats as $hat4) { foreach($hats as $hat5) { echo $hat1." ".$hat2." ".$hat3." ".$hat4." ".$hat5.PHP_EOL; } } } } } Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088675 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 How should i incorperate that in to a table that has the days of the week as headings and numbers down the side? Also how dose this work? Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088680 Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 Come on... is it that difficult to add <tr> and <td> tags to this echo? And as far as foreach goes... here's manual: foreach I've created a recursive function in the meantime, but I'm afraid of even showing it to you... Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088683 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 Why would you be afraid of showing me? Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088685 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 Also when i am trying to add numbers to it i get this error Parse error: syntax error, unexpected $end in C:\xampp\htdocs\mathstatment.php on line 56 my code: $hats = array('pink','brown','blue','red'); $i = 1; foreach($hats as $hat1) { foreach($hats as $hat2) { foreach($hats as $hat3) { foreach($hats as $hat4) { foreach($hats as $hat5) { echo $i . $hat1 . " " . $hat2 . " " . $hat3 . " " . $hat4 . " " . $hat5 . PHP_EOL . '<br />'; $i++; } } } } Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088687 Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 That's exactly why. Count the braces. Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088690 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 fixed it =] Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088691 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 where should i put the PHP_eol in my table? also what dose that function do(i cant find it on the manual) Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088692 Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 I gave you a direct link to foreach manual page... how can you not find it? PHP_EOL is a line break. I use it because I ran this script in console. For HTML you should use <br/> Here's my recursive function if you're interested: <?php function permute($array,$positions,&$perms,$previous = null) { if($positions > 0) { if(!isset($previous)) { $previous = array(); } foreach($array as $element) { $tempPrevious = $previous; $tempPrevious[] = $element; permute($array,$positions-1,$perms,$tempPrevious); } } else { $perms[] = $previous; } } $perms = array(); $hats = array('pink','brown','blue','red'); $days = 5; permute($hats, $days, $perms); echo "<table>"; foreach($perms as $key => $row) { echo "<tr><td>".($key+1)."</td>"; foreach($row as $hat) { echo "<td>$hat</td>"; } echo "</tr>".PHP_EOL; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088693 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 This is mine <html> <head> <title>Hats</title> <style type="text/css"> th { background-color: #999;} .odd_row { background-color: #EEE; } .even_row { background-color: #FFF; } </style> </head> <body> <table border="0"> <tr> <th>Number</th> <th>Monday</th> <th>Tuseday</th> <th>Wesnesday</th> <th>Thesday</th> <th>Friday</th> </tr> <?php /* Rules: 1 hat must be worn all day A hat must be worn every weekday Cant change hat once put on in the moring Mathmatical Statment 4*4*4*4*4 = 1024 What is going to happen: Every statment will be echoed out E.G: <table> <tr> <th>Monday</th> <th>Tuseday</th> <th>Wesnesday</th> <th>Thesday</th> <th>Friday</th> </tr><tr> <td>Pink</td> <td>Brown</td> <td>Blue</td> <td>Red</td> <td>Red</td> </tr> </table> */ $hats = array('pink','brown','blue','red'); $i = 1; foreach($hats as $hat1) { foreach($hats as $hat2) { foreach($hats as $hat3) { foreach($hats as $hat4) { foreach($hats as $hat5) { echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; echo <<<ENDHTML <td>{$i}</td> <td>{$hat1}</td> <td>{$hat2}</td> <td>{$hat3}</td> <td>{$hat4}</td> <td>{$hat5}</td> </tr> ENDHTML; $odd = !$odd; $i++; } } } } } ?> </table> </body> </html> Thanks for the help Jragon Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088697 Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 For ultimate fun do echo <<<ENDHTML <td>{$i}</td> <td style="background: {$hat1};">{$hat1}</td> <td style="background: {$hat2};">{$hat2}</td> <td style="background: {$hat3};">{$hat3}</td> <td style="background: {$hat4};">{$hat4}</td> <td style="background: {$hat5};">{$hat5}</td> </tr> ENDHTML; Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088712 Share on other sites More sharing options...
Jragon Posted July 20, 2010 Author Share Posted July 20, 2010 Thats cool! is there anyway to change the text color cos its a little hard to read Link to comment https://forums.phpfreaks.com/topic/208298-very-advance-math/#findComment-1088747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.