I am using a jQuery autocomplete script but the problem is I do not know what to add correctly inside the search.php file.
this is tutorial jQuery
<?php
$q = strtolower($_GET["q"]);
if (!$q) return;
$items = array(
"Peter Pan"=>"peter@pan.de",
"Molly"=>"molly@yahoo.com",
"Dr. Write"=>"write@writable.com"
);
$result = array();
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) {
array_push($result, array(
"name" => $key,
"to" => $value
));
}
}
echo json_encode($result);
?>
a working JSON for this jquery is as follow
[
{
label: "anna c13",
category: "Products"},
{
label: "john black",
category: "Products"},
{
label: "anders andersson",
category: "People"}
]
How can I convert my JSON into array like above?
Thank you.
Your PHP should create an Array which itself contains a series of associative arrays. You should then pass that through
json_encodeand send it to the browser.Run the code
http://codepad.org/ibD8kGWG
Code