JREAM Posted February 6, 2009 Share Posted February 6, 2009 I can't seem to get these Arrays to separate. if $first_listed_mp3s' are found in $data[$i] -- Don't list in File. So I would do an if statement inside the while loop and make $data[$i] = ''; if it is found, but I cant get anything to work. 1. I'm trying to have the top items at the top of the file, 2, and the rest of them listed below in whatever order they fall, 3. but I don't want the files listed twice and thats what is happening. <?php function list_mp3s () { // Set Directory and Options $directory = 'public/mp3s/'; $handler = opendir($directory); $fp = fopen('public/apps/mp3_player/playlist.xml', 'w'); // Write the data as blank, incase new files are added. $data = ''; // Start the top of the File $top_of_file .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $top_of_file .= "<xml>\n"; fwrite($fp, $top_of_file); // 111111111111111111111111111111111111111111 // Write the Top songs to Display $first_listed_mp3s = array( 'DREAM_ON.mp3', 'STRAY_DOG.mp3', 'JOLIE.mp3', 'AMERICAN_TRUCKER.mp3', 'LOTTIE.mp3', 'BYE_BABY.mp3', 'FIRE_IN_THE_SUN.mp3', 'JANE_AND_ME.mp3', '', ); for ($i = 0; $i < count($first_listed_mp3s); $i++) { $top_data[$i] .= "\n<track>\n"; $top_data[$i] .= "<path>$directory$first_listed_mp3s[$i]</path>\n"; $top_data[$i] .= "<title>".ucwords(strtolower(str_replace("_"," ", str_replace(".mp3","", $first_listed_mp3s[$i]))))."</title>\n"; $top_data[$i] .= "</track>\n"; fwrite($fp, $top_data[$i]); } // Counter $i = 0; // 222222222222222222222222222222222222222 // Function Power while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { $data[$i] .= "\n<track>\n"; $data[$i] .= "<path>$directory$file</path>\n"; $data[$i] .= "<title>".ucwords(strtolower(str_replace("_"," ", str_replace(".mp3","", $file))))."</title>\n"; $data[$i] .= "</track>\n"; // Count Individual File $i++; } } print_r(array_diff($top_data, $data)); // Write Array one by one for ($i = 0; $i < count($data); $i++) { fwrite($fp, $data[$i]); } $bottom_of_file .= "\n\n</xml>\n"; fwrite($fp, $bottom_of_file); fclose($fp); // Close Entire Directory closedir($handler); } // do it list_mp3s(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/144013-separating-arrays/ Share on other sites More sharing options...
sasa Posted February 6, 2009 Share Posted February 6, 2009 look in_array() function Quote Link to comment https://forums.phpfreaks.com/topic/144013-separating-arrays/#findComment-755671 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.