Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
octal
decimal
communitycreator

What is the octdec() method in PHP?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

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_string argument are skipped.

From PHP 7.4.0, any invalid characters in octal_string are deprecated.

  • The octal_string argument 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.

RELATED TAGS

php
octal
decimal
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring