Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:40:50+00:00 2026-06-12T14:40:50+00:00

How to assign PHP array values to JavaScript array? Using below PHP code I

  • 0

How to assign PHP array values to JavaScript array?

Using below PHP code I am storing data in PHP array:

<?php
$str_query="SELECT title,description FROM tablename ORDER BY title";
$rs_sch=GetRecordset($str_query); 

$int_count=0;
$schd_arr = array();
while(!$rs_sch->EOF())
{
$schd_arr[$int_count] = $rs_sch->Fields("title").": ".$rs_sch->Fields("description");
$rs_sch->MoveNext();
$int_count++;
}
?> 

Using below JavaScript code I am trying to store PHP array data into JavaScript array

What and how to write variable at below 2 mentioned locations so my code can work?

<script type="text/javascript" language="javascript">
var pausecontent=new Array()
for (sch_cnt=0; sch_cnt<*Here I want to assign value of $int_count php variable*; sch_cnt++)
{
pausecontent[sch_cnt]=<?php *Here I want to assign php array and counter values (something like this - $schd_arr[sch_cnt];)* ?>;
}
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:40:51+00:00Added an answer on June 12, 2026 at 2:40 pm

    You can’t loop like that, you need to loop the PHP array and push into javascript array:

    <script type="text/javascript" language="javascript">
        var pausecontent = new Array();
        <?php foreach($schd_arr as $key => $val){ ?>
            pausecontent.push('<?php echo $val; ?>');
        <?php } ?>
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my code where the php array $keys assigned to a JS array
How can I assign query result into array elements? This is my code: include('db.php');
jQuery.get(ChkNewRspLive.php?lastmsgID= + n, function(newitems){ //some code to separate values of 2d array. $('#div1').append(msgid); $('#div2').append(rspid);
I am using jQuery, JavaScript and PHP. My Ajax.php file just displays the data.
Is there a way to assign values in a JavaScript array in the way
Is it possible to assign php array in MySQL IN() function? for example, $numbers
My PHP code assigns an array to a Smarty variable that can be accessed
To assign specific value to 1D array I'm using LINQ like so: int[] nums
How do you assign the data fetched via getJSON() to an array, for later
I have an array $lines in php. Currently I want to assign the $lines

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.