MainelyDesign.com Blog

How do I reset the keys in a PHP array?

Posted on 09/11/2009 at 02:00 pm by Kevin Wentworth
Viewed 3,804 times | 1 comment

This answer was located at CodingForums.com on 9/11/09.  Answers written by PHP6 and Fou-Lu.
I had been hunting for an answer to the elusive question of how do I reset array keys in PHP.  I finally found the perfect (and thorough) answer here. There are 3 ways to reset array keys in PHP.  All of these solutions work with numerically indexed arrays only. To recap:

PHP Function: array_values()

  1. $reset_array_keys = array_values($numerically_indexed_array);

PHP Function: array_merge()

  1. $reset_array_keys = array_merge($numerically_indexed_array);

Foreach loop (aka kindergarten method)

This was the way I was going to reset the keys, but couldn't bring myself to doing it, as the name above implies.

  1. $reset_array_keys = array();
  2. foreach($numerically_indexed_array as $value) {
  3.     $reset_array_keys[] = $value;
  4. }

Cheers,

-Kevin Wentworth


Answers written by PHP6 and Fou-Lu. See Answer #4 and #6 in context at Coding Forums.

 

Bookmark and Share

Tags for How do I reset the keys in a PHP array?

Forum Answers

Comments for this Posting

Posted by Byron

on 7/7/11

J'aime vraiment votre article. J'ai essaye de trouver de nombreux en ligne et trouver le v?tre pour ĂȘtre la meilleure de toutes.

Mon francais n'est pas tres bon, je suis de l'Allemagne.

Mon blog:
rachat des credit et Rachat De Credit pour locataire

fr.wikipedia.org/wiki/Credit_immobilier

Sorry, comments are closed for this posting.

Please Email Kevin if you have any questions. Thanks!

Meet Site Avenger - Hosted Content Management System

Powered By: Site Avenger | Site Production: Saco Design