Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6228503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:24:03+00:00 2026-05-24T09:24:03+00:00

I am using a jQuery autocomplete script but the problem is I do not

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:24:03+00:00Added an answer on May 24, 2026 at 9:24 am

    Your PHP should create an Array which itself contains a series of associative arrays. You should then pass that through json_encode and send it to the browser.

    Run the code

    http://codepad.org/ibD8kGWG

    Code

    <?php
    //outer array
    $responseCollection = Array();
    
    
    //logic to ceate inner arrays:
    for( $i = 1; $i < 5; $i++ )
    {
      $responseCollection[] = Array(
        'label' => 'label ' . $i,
        'category' => 'category ' . $i
      );
    }
    
    //json encode it
    $json = json_encode( $responseCollection );
    
    echo $json;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using the jquery auto complete script like this $(#ac1).autocomplete('search.php'); And it is
I am using this jquery ui autocomplete but i need to grab the data
I am using jQuery Autocomplete with JSON but the resulting data is not displaying
I am using jQuery auto-complete. I have download this script from http://code.google.com/p/jquery-autocomplete/ . I
I'm using jquery autocomplete <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script> <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'></script> Everything is working Ok., but now
Am using JQuery Autocomplete on my templete, but as i get the results the
I'm using jQuery AutoComplete, and I have an auto-complete search box to search for
I'm using jQuery UI, specifically Datepicker and Autocomplete, as follows: <script src=http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js></script> <link href=http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css
Im currently using the JQuery UI extension for its search autocomplete. However, I need
i am using JQuery UI Autocomplete with asp.net textbox. AutoComplete works right. but how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.