php array_unique方法“将键放入数组”

Im going to parse json to my array by unique values. But here is some problem about array_unique function. For example:

$contract_types = [ "Asset Sale and Purchase Agreement", "Asset Sale and Purchase Agreement", "Concession Agreement" ];

and

return array_unique($contract_types);

gives me: [{ "0": "Asset Sale and Purchase Agreement", "2": "Concession Agreement" }]

What i'm doing wrong?

array_unique() preserves keys. From PHP docs:

Note that keys are preserved.

If you wish to reindex the array so it has consecutive integer indexes, use array_values():

return array_values(array_unique($contract_types));

You mean that your keys are 0, 2 and you wish you had 0,1 ?

If so, perform a array_values :

$contract_types = array_unique($contract_types);

return array_values($contract_types);