I have a variable in javascript and a multidimensional array in PHP. I want to check the information contained in the PHP array to see which elements contain the equivalent of the the javascript variable, and then display those elements. I’m not sure what the best way to do this is.
I’m inclined to convert the PHP array to a js array of objects (remember, it’s multidimensional) and do the comparison in javascript, and then use jQuery to output the right elements. But that all seems like a pretty big hassle for what seems like a pretty simple problem.
Is there a better way?
The two scripts, your PHP script and your JavaScript, are executed at different times. So, how is your PHP supposed to know what value is stored in the JavaScript variable? By a POST or GET to the PHP script. Once you do that, your PHP script can do the comparison and return the results in whatever format you wish (e.g. JSON).