Jump to content

[HELP] with Operators


joomador

Recommended Posts

Hi guys!

 

I am trying to understand why the final value of $m equals 40 in the following code

 

<?php
$i = 29;
$j = 11;
$m = 10;

$j = ($j - 4) / 2;
$m += $j * 10;
echo "m = ".$m."<br>"; //Equals 40
?>

 

Can anyone explain me please? I feel very confused right now.  :wtf:

Link to comment
Share on other sites

It would be 40 if the division was integer division.  But php doesn't use integer division.  From the manual:

 

There is no integer division operator in PHP. 1/2 yields the float 0.5. The value can be casted to an integer to round it downwards, or the round() function provides finer control over rounding.
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.