Steps to convert a decimal number to octal number:
1. Take modulas(%) of decimal number by 8.
2. Now divide decimal number by 8.
3. Repeat these steps until condition matches.
4. Now reverse that number.
Go through the code given below.
<?php
$numberToConvert = 78;
if($numberToConvert > 0){
$tempArray = array();
echo "Octal of $numberToConvert is : ";
while($numberToConvert){
$tempArray[] = $numberToConvert%8;
$numberToConvert = (int)($numberToConvert/8);
}
for($i = count($tempArray); $i >=0; $i--){
echo $tempArray[$i];
}
}else{
echo 'Number should be greater then zero.';
}
?>