Hi all im having slight trouble trying to escape this php array index in a javascript block

<script>
    var herp = $('#item').val(); 
    var derp = '<?php echo $array['+herp+']['0']['name'];?>';  
</script>

problem is the browser keeps making the whole line php, oposed to counting the var herp as javascript.

any ideas how to correctly escape this?

-Cheers
Soapy!

Member Avatar for LastMitch

problem is the browser keeps making the whole line php, oposed to counting the var herp as javascript.

Is the loop code in PHP or javascript? You never mention it. Post you array loop code.

Why is there a plus sign:

$array['+herp+']
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.