what will be the output of the following and why ? $x=025 echo $x/5; The question deals with php and brings the different between 025 and 25 when divided by 5.
Asked
Active
Viewed 567 times
-1
-
Why don't you try it out yourself? That code will produce a "_Parse error: syntax error, unexpected token "echo" ..._" – brombeer Nov 29 '21 at 11:43
-
When you prefix a number with a zero, like `$x = 025;`, PHP will read it as an octal number. Octal `25` is equal decimal `21` so the code above is equal to: `$x = 21; echo $x / 5;` which will be `4.2` – M. Eriksson Nov 29 '21 at 11:44
-
the output is 4.2 – Albert Logic Einstein Nov 29 '21 at 11:44
1 Answers
1
The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7, that is to say 10 represents 8 in decimal and 100 represents 64 in decimal.
25 = Whole
025 = Octal
025 in octal system = 21
so 21/5 = 4.2

Albert Logic Einstein
- 705
- 9
- 17