How can the memory limit be set in the php.ini file to prevent memory exhaustion errors?

Memory exhaustion errors can occur when a PHP script uses more memory than the limit set in the php.ini file. To prevent these errors, you can increase the memory limit in the php.ini file by editing the "memory_limit" directive. By setting a higher memory limit, you can ensure that your PHP scripts have enough memory to run without encountering memory exhaustion errors.

// Set memory limit to 256MB in php.ini file
ini_set('memory_limit', '256M');