{"id":1192,"date":"2013-07-29T23:46:06","date_gmt":"2013-07-29T23:46:06","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1192"},"modified":"2013-07-29T23:49:41","modified_gmt":"2013-07-29T23:49:41","slug":"how-to-make-a-json-object-with-php-array-for-jquery-autocomplete","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2013\/07\/how-to-make-a-json-object-with-php-array-for-jquery-autocomplete\/","title":{"rendered":"How to make a JSON object with PHP array for jQuery autocomplete?"},"content":{"rendered":"<p>This php code creates JSON object like \u201d availableTags \u201c<\/p>\n<pre lang=\"js\">\r\n\tvar availableTags = [\r\n\t{key: \"1\",value: \"NAME 1\"},{key: \"2\",value: \"NAME 2\"},{key: \"3\",value: \"NAME 3\"},{key: \"4\",value: \"NAME 4\"},{key: \"5\",value: \"NAME 5\"}\r\n\t ];\r\n\r\n<\/pre>\n<p>$Acc_Name_List is your PHP array which have key and value. You can manipulate as you want, make function or add into your class.<\/p>\n<pre lang=\"php\">\r\n            var availableTags = [\r\n                <?Php\r\n                foreach ($Acc_Name_List as $key=>$value_name)\r\n                {\r\n                  if ($key != 0 && $key != \"\" && $value_name != \"\")\r\n                  {\r\n                   $list_key = \"key: \". '\"'.$key.'\"';\r\n                   $list_value = \"value: \". '\"'.$value_name.'\"';\r\n                   \/\/ $string .= $list_value.',';\r\n                     $string .=\"{\". $list_key.','.$list_value.\"},\";\r\n                  }\r\n                }\r\n                $string = substr($string, 0, -1);\r\n               \/\/ echo $result;\r\n                echo $string;\r\n                ?>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This php code creates JSON object like \u201d availableTags \u201c var availableTags = [ {key: &#8220;1&#8221;,value: &#8220;NAME 1&#8221;},{key: &#8220;2&#8221;,value: &#8220;NAME 2&#8221;},{key: &#8220;3&#8221;,value: &#8220;NAME 3&#8221;},{key: &#8220;4&#8221;,value: &#8220;NAME 4&#8221;},{key: &#8220;5&#8221;,value: &#8220;NAME 5&#8221;} ]; $Acc_Name_List is your PHP array which have key and value. You can manipulate as you want, make function or add into your class. var [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[30],"tags":[],"class_list":["post-1192","post","type-post","status-publish","format-standard","hentry","category-jquery"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=1192"}],"version-history":[{"count":4,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1192\/revisions"}],"predecessor-version":[{"id":1196,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1192\/revisions\/1196"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}