PHP: Convert CSV String to a Pretty Assoc Array
Submitted by admin on Mon, 09/08/2025 - 9:05amSometimes you find yourself with a CSV string (not a file on the filesystem), and you'd like to use str_getcsv to get an array, but the results are sloppy and not at all friendly to work with. Reading from a file on the filesystem is more memory-friendly, but sometimes that just isn't the situation you have.
If you think this applies to you, check out the following function.
It creates an assoc array from a CSV string, where the header value is used as the array's keys.