What could be causing the "Memory Limit exhausted" error in PHP when running a script on a web server?

The "Memory Limit exhausted" error in PHP occurs when a script consumes more memory than the limit set by the server configuration. This can happen due to inefficient code, large data processing, or recursive functions. To solve this issue, you can increase the memory limit in the php.ini file or optimize the script to use memory more efficiently.

// Increase memory limit in PHP script
ini_set('memory_limit', '256M');