0
Array
(
    [0] => giri
)
Array
(
    [0] => ramya
)
Array
(
    [0] => sangeetha
)
Array
(
    [0] => hemalatha
)
Array
(
    [0] => umar
)

How to convert this PHP array into a Javascript array like below?

var availableTags = [
    "ActionScript",
    "AppleScript",
    "Asp",
    "BASIC",
    "C",
    "C++",
    "Clojure",
    "COBOL",
    "ColdFusion",
    "Erlang",
    "Fortran",
    "Groovy",
    "Haskell",
    "Java",
    "JavaScript",
    "Lisp",
    "Perl",
    "PHP",
    "Python",
    "Ruby",
    "Scala",
    "Scheme"
];
2

2 Answers 2

2

simple use the json_encode() function.

<?php 
$array = array('element' => 'value', 'element2' => 'value2');
print json_encode($array);
?>
0

Use json_encode() function to convert PHP data structures to JavaScript arrays/objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.