How can the memory limit be increased in the php.ini or Apache Directives to avoid memory exhaustion errors in PHP?

Memory exhaustion errors in PHP can be avoided by increasing the memory limit in the php.ini file or Apache Directives. To increase the memory limit, you can edit the php.ini file and set the `memory_limit` directive to a higher value. Alternatively, you can also use the `ini_set()` function in PHP to dynamically increase the memory limit within your script.

// Increase memory limit in php.ini
ini_set('memory_limit', '256M');