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 6756533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:32:09+00:00 2026-05-26T13:32:09+00:00

I assigned php value into JS variable by jQuery.parseJSON. After that, Converting an array-like

  • 0
  1. I assigned php value into JS variable by jQuery.parseJSON.
  2. After that, Converting an array-like object(i.e. cars) into a true JavaScript array(i.e. carsArr) by jQuery.makeArray().
  3. Then I want to get the 1st array(i.e.carsArr[0])of carsArr variable which should be array type as well.

However, the alertbox shows it’string type.

So how can i get the 1st array of carsArr variable? Thanks!

<?php
    $car1=array("Saab","Volvo","BMW");
        $car2=array("123","234","345");

        $cars = array($car1, $car2);
?>

<script type="text/javascript">
    $(function () {

        var cars =jQuery.parseJSON('<?php echo json_encode($cars); ?>');

        var carsArr =jQuery.makeArray(cars);

    var aCar = carsArr[0];

    alert(typeof(aCar));

    });
</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-05-26T13:32:09+00:00Added an answer on May 26, 2026 at 1:32 pm

    Looks like you are doing javascript like variable assignment in PHP

    Change $cars = array(car1, car2);

    To $cars = array($car1, $car2);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an PHP array that looks something like this: Index Key Value [0]
Below is my code where the php array $keys assigned to a JS array
In PHP, I have an associative array like this $a = array('who' => 'one',
I have an Entity class that looks like this: <?php namespace Entities; /** @Entity
I have been assigned a project to develop a set of classes that act
Recently I just got assigned a project to develop a web application/site that uses
I have been assigned wit the task to write a program that takes a
I have the following jQuery script: $(document).ready(function() { $.ajax({ url: 'temp.ajax.php', type: 'GET', success:
In PHP I have an array containing 20 elements or more. The keys have
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.