From PHP I am pushing a basic array to jQuery via wp_localize_script()
and then using the array data in my script file.
Now I have extended the array into a multidimensional array and can not figure out how to get the data out of the array to use in in the javascript file.
Currently I'm extracting the data from the array is like this:
jQuery(document).ready(function($){
var optionA = theme_metadata.dataA;
var optionB = theme_metadata.dataB;
theme_metadata
is the array that I built in PHP and push to jQuery via wp_localize_script()
.
dataA
and dataB
are keys in the array.
My new array looks like this:
[theme_meta] => Array
(
[0] => Array
(
[dataA] => foo
[dataB] => bar
)
[1] => Array
(
[dataA] => this
[dataB] => that
)
)
How do I setup my var in the script file to read [theme_meta][0][dataB]
?
Also how can I loop through the array? The numbered key index will not be known, i.e., [0]- whatever [100]
?
I could send over a key=>value
on how big the array is as a stopping point for a loop, i.e., 'theme_meta_size' => 2
as in the sample array.