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?

Omar Ali
  • 8,467
  • 4
  • 33
  • 58
Raghul Rajendran
  • 486
  • 2
  • 7
  • 25
  • 4
    `$event = array_values(array_unique($array_event));` – cske Nov 15 '16 at 14:46
  • thanks you. now its working – Raghul Rajendran Nov 15 '16 at 14:48
  • Possible duplicate of [Converting Object to JSON and JSON to Object in PHP, (library like Gson for Java)](http://stackoverflow.com/questions/9858448/converting-object-to-json-and-json-to-object-in-php-library-like-gson-for-java) – Travis Heeter Nov 15 '16 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 – cske Nov 15 '16 at 15:43
  • 1
    @RaghulRajendran you shoud mention in question that your are asking about the json_encod-ed output `json_encode($event)` – cske Nov 15 '16 at 15:44

1 Answers1

1

You shoud reindex result before json_encode

$event = array_values(array_unique($array_event));
cske
  • 2,233
  • 4
  • 26
  • 24