My question may not make sense, but after trying all kinds of array_chunk, and explodes, I can't seem to find an easy way to solve my issue.
Ultimately, I have a textarea that I want to be able to enter data like this:
<textarea>
Song 1 by Artist 1
Song 2 by Artist 2
Song 3 by Artist 1
Song 4 by Artist 3
Song 5 by Artist 3
</textarea>
I want to ultimately create an array that I can filter and loop out, and grab each song title and artist title, and have a nested array.
So far, I can use explode( "\n", $source) to create a simple array:
array (size=5)
0 => string 'Song 1 by Artist 1' (length=19)
1 => string 'Song 2 by Artist 2' (length=19)
2 => string 'Song 3 by Artist 1' (length=19)
3 => string 'Song 4 by Artist 3' (length=19)
4 => string 'Song 5 by Artist 3' (length=18)
But I want to now further create an array inside this for each song title and artist title so it will look like:
array (
0 => array(
'title' => 'Song 1',
'artist' => 'Artist 1
),
1 => array(
'title' => 'Song 2',
'artist' => 'Artist 2
)
etc.
How can I expand the initial explode function to be able to loop out the final array values as a list?