Remove keys from an associative array in PHP

Today we’ll write a short article on how to remove keys from an associative array in PHP and get an array without keys to return a new reindex array which starts with index 0.

Refer the article to get keys from an associative array in PHP.

Ways to remove keys from associative array

  1. Using built-in function
  2. Using custom function

1. Using built-in function

We have built-in array_values() function to remove the keys and re-create the array with new keys starting from 0. It returns an indexed array of values.

Syntax:

Parameter:

It required only a single parameter that specifies the array. Refer to the following example.

Example:

2. Using custom function

We can also remove the keys and get an array values using foreach loop with custom function.

That’s it for today.
Thank you for reading. Happy Coding..!!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *