javascript - jQuery: set 'selected' tag in options if value is in array -


I am trying to add the selected attribute to the option The tag using jQuery (those on a Wordpress site) those values ​​that should be selected are stored in the PHP array. The selected attribute is & lt; Options & gt; .. ?

Why is not added to my-script.js each function ($) {var arr = [& lt ;? Php echo '' '.implode (' ", '', $ php_array)

  jQuery (" # location options "). ''? & Gt;]; // for test Also the hardcode array is: // var arr = ["1", "2"]; if (jQuery.inArray ($ (this) .val (either)), ARM! = -1) {$ (this). Attr ('selected', 'selected');};});   

.js The script is enqueqed properly.

< Strong> html-output