How can the memory limit be adjusted in PHP when facing memory size exhaustion errors?

Memory size exhaustion errors in PHP can be adjusted by increasing the memory limit in the php.ini file or within the script using the ini_set() function. This can help prevent errors such as "Allowed memory size exhausted" when dealing with large amounts of data or resource-intensive operations.

// Increase memory limit to 256MB
ini_set('memory_limit', '256M');