Search code examples
phpcodeigniterarray-unique

array_unique - php - codeigniter


$skillsarray = ["php","java","ios","php","php","php","php","java","java","ios"];

$cityarray = ["Chennai","Theni","Theni","Mumbai","Chennai","Theni","Chennai","Hyderabad","Theni","Madurai"];

If I used array_unique for $skillsarray, getting result as

["php","java","ios"]

If I used array_unique for $cityarray, getting result as

{"0":"Chennai","1":"Theni","3":"Mumbai","7":"Hyderabad","9":"Madurai"}

Can anyone explain why the array_unique($cityarray) is producing dictionary result?


Solution

  • array_unique find first unique values from the array with id and that is the reason $cityarry is different from $skillarray. Please check image that will easy to understand...:)