I'm building a website and I have some data within php variables. I'm trying to use that data for jQuery engine for Java enabled browsers.
I came across the problem with using php variables within jQuery script:
Here's the code I can't get to work.
//PHP array:
$filters['ab']='text a';
$filters['cd']='text b';
// jQuery script:
// Key I want to find in array
var test = "ab";
// Reading php array into JSON
filters = $.parseJSON('<?php echo json_encode($filters); ?>');
// Trying to use JSON data to create Array using original keys and values
var filtersArray = new Array();
$.each(filters, function(key) {
filtersArray[key] = $(filters).attr(key);
});
alert(filtersArray['ab']); returns "text a"; // Seems to be working
// Trying to find the test variable value
filterIndex = $.inArray(test, filtersArray) // Not found
Sorry for previous careless version of post. I though shorter will be better, but in fact it came out completely useless.
Thanks