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_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.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources