How can PHP limits be utilized to manage memory usage when dealing with large datasets?

When dealing with large datasets in PHP, memory usage can quickly become a concern. To manage memory usage, PHP limits can be utilized to restrict the amount of memory a script can consume. By setting limits on memory usage, you can prevent memory exhaustion and potential crashes when working with large datasets.

// Set a memory limit of 128MB
ini_set('memory_limit', '128M');

// Code to handle large datasets goes here