I've got a foreach loop that produces a string in php , I am not able to pass through the string value to mootools in wordpress (I am integrating a MooTool function ) :::

I have to substitute the "hard coded" image URL's within the new Array() (below) having a variable produced from the php string eg. new Array( $myimageurl ) :::

I have produced a var in the php string even attempted json_scribe , without any luck :::

window.addEvent("domready", function(){
var counter = 0;
var images = new Array('http://localhost/square/wp-content/uploads/2011/10/test-foo/foo.jpg','http://localhost/square/wp-content/uploads/2011/10/test-foo/foo1.jpg');

er, why don't you just:

var foo= <?=json_encode(Array("foo.jpg", "bar.jpg"))?>;


Because you implied inside a comment your files source is comma separated, then do that rather:

<? $files = "foo.jpg,bar.jpg"; ?>
var foo = <?=json_encode(explode(',', $files))?>;

in which the array might be anything associated with a length, read no matter where. it can lead to an assortment literal searching like so:

var foo = ["foo.jpg","bar.jpg"]; 
// eg use. 
foo.each(function(img) {
    new Element("img", {src: img}).inject(document.body);

nb: just observed @Marc B has pointed out json_scribe. sorry, will remove


var images = new Array('<?php echo $miImageUrl[0];?>', '<?php echo $miImageUrl[1];?>');


//sample data
$descargables[0] = 'cero';
$descargables[1] = 'uno';
$descargables[2] = 'dos';
$descargables[3] = 'tres';
// end sample data

$arrayToJs="var descargables = new Array();";
for ($i=0; $i < count($descargables); $i++) {
    $arrayToJs .= "descargables[" . $i . "]='" . $descargables[$i]. "';";


<?php echo $arrayToJs;?>
idx = 3;
alert("descargable:" + descargables[idx]);