Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Fatal Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) on line 3

Ask Question

I am getting this error in codeigniter 3. I had tried most of the things but none of them worked.

    function money_format($num = 0, $pro = 2)
        %number =round((float)$num, $pro);
         if($pro == 2)
            $num = money_format("%!^2n",(float)$num);
            $num = money_format("%=*!^.".$pro."n",(float)$num);
         return $num;

This is a recursive function without a stop condition. This will lead to an infinite loop. It'll always calls itself until there is no memory left.

If I could suggest an alternative, I would say to use the number_format function to format numbers. Its a native php function and really simple to use. Take a look at the documentation.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.