Home » , » Assign a php array to a jquery variable

Assign a php array to a jquery variable

Written By Unknown on Sabtu, 19 Oktober 2013 | 03.48

To assign php array to jquery variable use

var jArray= <?php echo json_encode($phpArray ); ?>;

jArray  is the jquery variable which hold array in jquery and
$phpArray contains my php array ...

-------------------------------------------------------------------------------------------------------------
For more details run below example:

<html>
<head>

</head>
<body>

<b> Hello .. Today we are assigning a php array to jquery variable <b>
<?php $phpArray = array(
          0 => "Mon",
          1 => "Tue",
          2 => "Wed",
          3 => "Thu",
          4 => "Fri",
          5 => "Sat",
          6 => "Sun",

    )
   

?>


</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
     var jArray= <?php echo json_encode($phpArray ); ?>;

    for(var i=0;i<6;i++){
        alert(jArray[i]);
    }
    alert("Refresh again to see Array-Data    ")
});
</script>
</html>


Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger