Jump to content

Convert Php Array To Jquery Array


mjcnyx

Recommended Posts

I have a simple PHP array such as: $arr = array("red car", "blue truck", "black jeep", "yellow bike"); I would like to convert this array to a JQuery array, but have no idea where to begin. Thanks for any advice in advance.

Link to comment
Share on other sites

You mean a Javascript array? jQuery is just a Javascript library.Just print out all the elements in a Javascript syntax.

echo 'var arr = [';$comma = false;foreach($arr as $item) {   // Make sure we don't add a comma before the first item of the JSON syntax array.  if($comma) {    echo ',';    $comma = true;  } echo " '{$item}' ";}echo ']';

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...