My code
<?php
var_dump('0xD' * 1 );
var_dump((int)'0xD');
var_dump(intval('0xD'));
var_dump((float)'0xD');
Actual result:
int(13)
int(0)
int(0)
float(0)
Why result of first two conditions are not same? Can you provide me correct documentation?
All that I found is
- Type Casting: Type casting in PHP works much as it does in C: the name of the desired type is written in parentheses before the variable which is to be cast. It may not be obvious exactly what will happen when casting between certain types. For more information, see these sections:...
- Converting to integer: From strings: See String conversion to numbers
- String conversion to numbers When a string is evaluated in a numeric context, the resulting value and type are determined as follows.
So, As far as I understand, docs say that casting to int directly and by putting in numeric context should be same. What is my mistake?
ADDED: Try to check first and second code (and outputs) before answering.