1

I've been converting some code from other languages (that are using algorithms) and adding them into PHP to some class code.

I came across some code that did the following line: (Python)

decNumber = decNumber // 2

I thought that it meant divide by two, but the outcome of adding this to my code was not as expected.

If this doesn't mean /2 in PHP form then is there a PHP equivalent for this?

Jack Hales
  • 1,533
  • 24
  • 46

1 Answers1

3

In PHP // means single line comment. The characters after // won't be executed.

You can use type casting in PHP for achieving the same. Below code will give you integer quotient.

<?php
$decNumber = 3;
$decNumber = (int)($decNumber / 2) ;
echo $decNumber;
?>

Output

1

Harikrishnan
  • 9,108
  • 9
  • 83
  • 125
  • I understand that in PHP, but in Python it's used in arithmetic and wondering if there is a PHP equivalent. – Jack Hales May 07 '16 at 04:50