I think you have typo in jQuery loop
jQuery("#location option").each(function($){
var arr = [<?php echo '"'.implode('","', $php_array).'"' ?>];
// for testing also hardcoded array: doesn't work either
// var arr = ["1", "2"];
if(jQuery.inArray($(this).val(),arr) != -1){
$(this).attr('selected', 'selected');
};
});
function($) should be without parameter, like this function()
Working code:
jQuery("#location option").each(function(){
var arr = [<?php echo '"'.implode('","', $php_array).'"' ?>];
// for testing also hardcoded array: doesn't work either
// var arr = ["1", "2"];
if(jQuery.inArray($(this).val(),arr) != -1){
$(this).attr('selected', 'selected');
};
});
my jsFiddle: http://jsfiddle.net/Cs329/