Jump to content

How do I put a Array inside a forloop?


Monkuar

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.