1

I'm using array_unique to remove the duplicate values but it returns an object format.

$event = array_unique($array_event);

output as

{"0":{"title":"new","description":"hai"},"4":null}

Excepted output:

[{"title":"new","description":"hai"},null}]

Can anyone help with this issue?

5
  • 4
    $event = array_values(array_unique($array_event)); Commented Nov 15, 2016 at 14:46
  • thanks you. now its working Commented Nov 15, 2016 at 14:48
  • Possible duplicate of Converting Object to JSON and JSON to Object in PHP, (library like Gson for Java) Commented Nov 15, 2016 at 15:08
  • 1
    @TravisHeeter not duplicate, refered only advises use of json_encode which it self those not produce the required output in this case Commented Nov 15, 2016 at 15:43
  • 1
    @RaghulRajendran you shoud mention in question that your are asking about the json_encod-ed output json_encode($event) Commented Nov 15, 2016 at 15:44

1 Answer 1

1

You shoud reindex result before json_encode

$event = array_values(array_unique($array_event));
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.