Tell me, please, why the script does not display the result of the conversion from the decimal system to the binary. What is wrong here?

<?php $bin = '101'; function myBin2Dec($bin) { $n = strlen((string)$bin); for ($dec = 0, $i = 0; $i < n; $i++) { $dec = 2 * $dec + (int)$bin{$i}; } echo "=======\n<br>bin = ".$bin."; base = 10\n</br>=======</br>"; return $dec; } $result = myBin2Dec($bin); echo "result = ".$result."\n</br>"; ?> 

    1 answer 1

    It was

     for ($dec = 0, $i = 0; $i < n; $i++) { 

    It became

     for ($dec = 0, $i = 0; $i < $n; $i++) { 

    My interpreter cursed:

    PHP Notice: Use of undefined constant n - assumed 'n' in / home / t / Documents / No name.php on line 27

    • Thank you very much for your help - andrey26rus