Jump to content

else that wont loop


maxwel

Recommended Posts

while(false!== ($file = readdir($res))) {
if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) {

if (($info["extension"] == "mp3") || ($info["extension"] == "wav")) {
}else{}
}
}

the problem is that when i put an error msg in the else of the red code part it loops as much as files that are not mp3 or wave type. so how i can stop that from happening? and if i did put it outside it wont read $file variable. or even is it possible to know how to make another variable that can bring results of my search outside the while loop cuz i tried alot of things but didnt work :S

 

Thanks in advance,

Maxwel

Link to comment
https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/
Share on other sites

Muddy_funster is right. You can set the error message in the loop and echo the error message after the loop completes:

while(false!== ($file = readdir($res))) {
if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude)) {

if (($info["extension"] == "mp3") || ($info["extension"] == "wav")) {
}elseif(!isset($errorMsg)){
  $errorMsg = "Your Error Message";
}
}
}// now we are out of the loop
if (isset($errorMsg)) echo $errorMsg;
Link to comment
https://forums.phpfreaks.com/topic/278319-else-that-wont-loop/#findComment-1431840
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.