Monkuar Posted March 4, 2012 Share Posted March 4, 2012 Okay, here is my code, it's messy but i will show u what needs to be done if u can help me $uservalue=$user['max_stars']; $numCols = 8; $numPerCol = ceil(75 / $numCols); echo "<table class=tuble><tr>"; for($col = 1; $col <= $numCols; $col++) { $numerals = array(1=>'I','II','III','IV','V','VI','VII','VIII'); echo "<td><dl><dt>{$numerals}</dt><dd>"; for($row = 0; $row < $numPerCol; $row++) { $resultRow = 75; if ($i<=$uservalue) { if ($i == $selected) { $checked = 'checked'; }else{ $checked = ''; } echo '<label for="s'.$i.'"><input type="radio" id="s'.$i.'" onclick=\'showPreview('.$i.')\' value="'.$i.'" '.$checked.' name="form[star]"><img src=img/icons/'.$i.'.png></label><br>'; } else { if ($i > 75){ $lol = array("hey","hey2"); foreach ($lol as $lols){ $lol .= $lols; } echo '<font color=#f36f6f><span class=desc><b><img src=img/icons/'.$i.'.png> Confidential</span></b></font><label for="s'.$i.'"><input type="radio" id="s'.$i.'" onclick=\'showPreview('.$i.')\' value="'.$i.'" name="form[star]" disabled></label><img src=img/lock2.png><br>'; }else{ echo '<label for="s'.$i.'"><input type="radio" id="s'.$i.'" onclick=\'showPreview('.$i.')\' value="'.$i.'" name="form[star]" disabled><img src=img/icons/'.$i.'.png></label><img src=img/lock.png><br>'; } } $i++; } echo "</td>"; } This code here: $numerals = array(1=>'I','II','III','IV','V','VI','VII','VIII'); echo "<td><dl><dt>{$numerals}</dt><dd>"; for($row = 0; $row < $numPerCol; $row++) { I need to echo out that $numerals array onto my $numerals variable, but I cant because it's under a for loop, and if i try using a foreach it wont display correctly. because it's already under a forloop Any idea guys? Link to comment https://forums.phpfreaks.com/topic/258259-how-do-i-put-a-array-inside-a-forloop/ Share on other sites More sharing options...
S3cr3t Posted March 4, 2012 Share Posted March 4, 2012 function romanNumerals($num) { $n = intval($num); $res = ''; /*** roman_numerals array ***/ $roman_numerals = array( 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1); foreach ($roman_numerals as $roman => $number) { /*** divide to get matches ***/ $matches = intval($n / $number); /*** assign the roman char * $matches ***/ $res .= str_repeat($roman, $matches); /*** substract from the number ***/ $n = $n % $number; } /*** return the res ***/ return $res; } echo romanNumerals(2012); Link to comment https://forums.phpfreaks.com/topic/258259-how-do-i-put-a-array-inside-a-forloop/#findComment-1323827 Share on other sites More sharing options...
Monkuar Posted March 4, 2012 Author Share Posted March 4, 2012 function romanNumerals($num) { $n = intval($num); $res = ''; /*** roman_numerals array ***/ $roman_numerals = array( 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1); foreach ($roman_numerals as $roman => $number) { /*** divide to get matches ***/ $matches = intval($n / $number); /*** assign the roman char * $matches ***/ $res .= str_repeat($roman, $matches); /*** substract from the number ***/ $n = $n % $number; } /*** return the res ***/ return $res; } echo romanNumerals(2012); Haha, I got the roman numerals working man $numerals = array(1=>'I','II','III','IV','V','VI','VII','VIII'); for($col = 1; $col <= $numCols; $col++) { echo "<td><dl><dt>{$numerals['1']}{$numerals['2']}</dt><dd class=padding>"; There is just no way to echo them out dynamically based on that $numerals array because I am already inside a for loop, any help? Link to comment https://forums.phpfreaks.com/topic/258259-how-do-i-put-a-array-inside-a-forloop/#findComment-1323829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.