0

How to create json object like this ? I want to make array and pass it in autocomplete function with json_encode

[
    {label:"Display Name for result 1", value:1},
    {label:"Display Name for result 2", value:2},
    {label:"Display Name for result 3", value:3}
]

1 Answer 1

2

PHP doesn't use json itself. Just make a regular php array and push it through the json_encode function.

$stuff = array(
  array( 'label' => 'name 1', 'value' => 1 ),
  array( 'label' => 'name 2', 'value' => 2 ),
  array( 'label' => 'name 3', 'value' => 3 ),
);
echo json_encode( $stuff );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.