I scan a directory with PHP which includes only folders:
$folders = scandir('gallery');
Now i want to check if a string in javascript a folder in this directory.
if(theString == allTheFolders){
alert('yay');
}
Now $folders is an array with strings in it. To get all the strings i use a foreach loop and ignore the '.' & '..' directory’s. But how can i get all these folders in the if loop?
Hope you understand my question!
Echo out your array as JSON, right into your JavaScript.
Then you can loop through or do whatever you need directly in JavaScript.
Edit: Now that you have posted your actual question… Do this in your JavaScript:
As an alternative, I would probably use
Array.indexOf(). It isn’t available in all browsers, but that problem is easily remedied. See the documentation: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf