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"
];
dda
6,2212 gold badges27 silver badges37 bronze badges
asked Feb 24, 2012 at 8:56
2
  • 5
    With json_encode. And try to spend at least 30 seconds formatting your question next time please.. Commented Feb 24, 2012 at 8:58
  • possible duplicate of PHP to Javascript Array (Kind of), Php pass array to Javascript, php array to javascript, and likely many others. In addition to formatting, it's good to spend a little time searching, which cuts down on noise. Commented Feb 24, 2012 at 9:44

2 Answers 2

2

simple use the json_encode() function.

<?php 
$array = array('element' => 'value', 'element2' => 'value2');
print json_encode($array);
?>
answered Feb 24, 2012 at 9:16
Sign up to request clarification or add additional context in comments.

Comments

0

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

answered Feb 24, 2012 at 9:15

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.