octdec() converts an octal string to its decimal value.
$octal = '100';
echo octdec($octal); // 64
<?Php
echo octdec(5); // Output 5
echo "<br>";
echo octdec(45); // Output 37
echo "<br>";
echo octdec(400); // Output is 256
echo "<br>";
echo octdec(657); // Output is 431
echo "<br>";
echo octdec(3000); // Output is 1536
?>
Syntax
int|float octdec(string $octal_number);
| Parameter | DESCRIPTION |
|---|---|
| $octal_number | Required : Octal number string as Input to convert to equivalent decimal base number. |
$octal = "12";
echo octdec($octal); // Output: 10 (Octal 12 is decimal 10)
$octal = "7654321";
echo octdec($octal); // Output: 2054353
$octal_values = ['10', '11', '12', '13'];
foreach ($octal_values as $oct) {
echo "Octal $oct = Decimal " . octdec($oct) . "<br>";
}
// Output:
// Octal 10 = Decimal 8
// Octal 11 = Decimal 9
// Octal 12 = Decimal 10
// Octal 13 = Decimal 11
$octal = "00077";
echo octdec($octal); // Output: 63 (Octal 77 is decimal 63)
Invalid characters should not be passed to octdec(). In current PHP versions, relying on invalid characters being ignored is deprecated.
$octal = '127';
if (preg_match('/^[0-7]+$/', $octal)) {
echo octdec($octal); // 87
}
function convertOctal($octal) {
return octdec($octal);
}
echo convertOctal("145"); // Output: 101
These examples show leading zeros, validated octal input, and use inside a helper function.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.