What is the octdec() method in PHP?
The octdec() method can be used to convert an octal string to a decimal number.
Syntax
octdec(string $octal_string): int|float
Parameters
- Any invalid characters in the
octal_stringargument are skipped.
From PHP 7.4.0, any invalid characters in
octal_stringare deprecated.
- The
octal_stringargument should be a type of string, otherwise unexpected results will be produced.
Return value
octdec returns the decimal number of type int or float, based on the size of the value.
Code
<?php$num = "70";echo "decimal value of ". $num. " is: ". octdec($num)."\n";$num = "77";echo "decimal value of ". $num. " is: ". octdec($num)."\n";$num = "100";echo "decimal value of ". $num. " is: ". octdec($num)."\n";$num = "107";echo "decimal value of ". $num. " is: ". octdec($num)."\n";?>
Explanation
In the code above, we use the octdec method to convert the octal strings of 70, 77, 100 and 107 into decimal representation.