Recent Posts
- (09/10) Fixing Warning: the ECDSA host key for 'github.com' differs from the key for the IP addressTAGS:Web Server Admin
- (12/26) CakePHP 3 - Getting List of Column Definitions from a Table (like schema())TAGS:CakephpCake3
- (09/14) Change Order of Loaded Behaviors in CakePHP 3TAGS:Cake3CakephpWeb ProgrammingPhp
- (05/29) CakePHP 3 - Accept JSON Header Only Working When Debug FalseTAGS:Web ProgrammingCakephpCake3
- (05/23) Remove All Events from Google Calendar (Reset Calendar)TAGS:Web ProgrammingPhp
- (11/08) Google Tag Manager (GTM) Not Firing Default PageView EventTAGS:Web ProgrammingJavascriptGoogle Tag Manager
- (10/13) In PHP, how do you get __toString() Magic Method Result without calling echo?TAGS:CakephpCake3Cakephp 13PhpWeb Programming
- (11/14) Getting output from shell_exec() at all timesTAGS:Web ProgrammingWeb Server Admin
Subscribe to my feed
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 30,466 times | 0 comments
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()
PHP Function: array_merge()
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.
- foreach($numerically_indexed_array as $value) {
- $reset_array_keys[] = $value;
- }
Cheers,
-Kevin Wentworth
Answers written by PHP6 and Fou-Lu. See Answer #4 and #6 in context at Coding Forums.
Tags for How do I reset the keys in a PHP array?
Comments for this Posting
No comments. Be the first to post a reply.
Sorry, comments are closed for this posting.
Please Email Kevin if you have any questions. Thanks!