Assign PHP array content to a JavaScript array

Sometimes we need to transfer the server side data to client side. Means we may need to transfer PHP variable or array values to Javascript variable or values. The following script will solve this problem very well.

$aDatas = array();
$aTitles = array();
$iMaxCount = 10;
for($iCount=0; $iCount< $iMaxCount; $iCount++)
{
$aDatas[$iCount] = $iCount +10;
$aTitles[$iCount] = 'Title'. $iCount;
}

?>

Make sure that you have given single quote before and after PHP tag, while assigning STRING values from PHP variables to JS.

Tags: ,

Leave a Reply

Recent Comments

  • registry fix programs: “Worked perfectly on my Windows VISTA & WINDOWS 7 PC. Fixed all the problems in a...
  • Host Gator deals: Good website. Added to Myspace!
  • Brittani Zufall: Thanks. I’m constantly interested in items and information on web site seo. You don’t...
  • computer technology information: Thanks I found just the info I already searched everywhere and just couldn’t...
  • TERESA HUTCHINSON: I have been looking around www.adiipl.com and really am impressed by the amazing content here. I...