Get array from a php, put it into an array in Unity?

This is my php script. I’m trying to make it get all songs in that folder on my website, then send it to unity, so unity can make a playlist and stream the songs one by one, to save memory. I’ve barely done any php, how would I get the array from the php and put it into one in Unity? It’s probably simple, but google doesn’t help me much atm.

if ($handle = opendir('Playlist/')) {
    echo "Directory handle: $handle

";
echo "Entries:
";

    while (false !== ($entry = readdir($handle))) {
        echo "$entry

";
}

    closedir($handle);
}

Sending data between php scripts and unity is normaly done using Get or Post Request via WWW or WWWForm classes. And you can’t send an array using that method, however you could send CSV (comma-separeted values) representing an array.

Add a comma in between all of your “echos”.

while (false !== ($entry = readdir($handle))) {
    echo $entry . ",";
}

And then in Unity you can easily retreive that data using a simple string.Split(‘,’) and convert it in an array

string url = "http://example.com/script.php";
WWW www = new WWW(url);
yield return www;

string[] songNames = www.text.Split(',');