I dun quite understand how this program works.......
Please advice...
What is the output of this program?

<html>
<!-- test01.php -->
<body>

   <?php 
      $x = 2;
      for ($i = 1; $i <= 6; $i++)
      {
          if ($i % 2 == 1)
          {
             $x++;
          }
          print $i . 'x' . $i * $x . " ";
      }

   ?>

</body>
</html>





*******
Answer: 

1x3  2x6  3x12  4x16  5x25  6x30

Please advice...
Thanks,

Tony

This sounds like a homework problem to me, maybe you should to a little more studying. Why else would you include the "answer."

This sounds like a homework problem to me, maybe you should to a little more studying. Why else would you include the "answer."

This is an example of the kind of question that might appear in the final exam and although I have done 4 weeks of PHP, I dun quite get the reason for the output, which was given by my prof...

Member Avatar for diafol

You've spent more time on daniweb than hitting your books. Not a bad thing to do, but you need to do your own work now.

Clue: what type of numbers does $i % 2 == 1 give you??

You've spent more time on daniweb than hitting your books. Not a bad thing to do, but you need to do your own work now.

Clue: what type of numbers does $i % 2 == 1 give you??

I guess, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, etc...
Am I correct?

Member Avatar for diafol

Give the man a cigar! Now work out the relationship to the output or series. Oops almost gave it away.

Give the man a cigar! Now work out the relationship to the output or series. Oops almost gave it away.

X = 2 rite,
Then howcome the answer to the code is:
1 x 3, 2 x6, 3 x 12, 4 x16, 5 x 25, 6 x30

x++(shouldn't it be 3, 5, 7, 9, 11, 13)

I am confused...

Member Avatar for diafol

X = 2 rite,
Then howcome the answer to the code is:
1 x 3, 2 x6, 3 x 12, 4 x16, 5 x 25, 6 x30

x++(shouldn't it be 3, 5, 7, 9, 11, 13)

I am confused...

Mais non, mon cheri.

You always admire what you really don't understand

It would be wrong of me to arrest your admiration.

Mais non, mon cheri.


It would be wrong of me to arrest your admiration.

Could you please help me one last time on this, I am really lost...

Thanks,

Tony

Member Avatar for diafol

Paid â bod yn wirion, gwranda, rwyt wedi derbyn sawl darn o god yn rhad ac am ddim, cer i wneud gwaith dy hun.

In a word, no.

I think your semester average has been bumped enough already. You get the grades you deserve at the end.

False dawns and dead ends are the making of men. What feeble excuse of a man shall you turn out to be if you continue to complete a crossword by first checking the answers?

Go forth and pound thy books.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.