note 107855 added to function.array-keys

From: Date: Sat, 10 Mar 2012 07:41:17 +0000
Subject: note 107855 added to function.array-keys
Groups: php.notes 
Request: Send a blank email to php-notes+get-186572@lists.php.net to get a copy of this message
I was trying to figure out how to normalize an array with numerical keys. Since I was doing for() for a lot of things, but only replacing it if the conditions were right, I wound up with off ball arrays I couldn't access. That being said, I looked for a method of normalizing the array and couldn't find one, so I built my own. I'm not sure how to go about making it recursive, but I didn't need that feature for my own, so I just went without recursion. //This will take array([5] => "test1", [4] => "test2", [9] => "test3") into array([0] => "test1", [1] => "test2", [2] => "test3") so you can access it easier. function normalize_array($array){ $newarray = array(); $array_keys = array_keys($array); $i=0; foreach($array_keys as $key){ $newarray[$i] = $array[$key]; $i++; } return $newarray; } ---- Server IP: 192.41.42.26 Probable Submitter: 68.107.190.28 ---- Manual Page -- http://www.php.net/manual/en/function.array-keys.php Edit -- https://master.php.net/note/edit/107855 Del: integrated -- https://master.php.net/note/delete/107855/integrated Del: useless -- https://master.php.net/note/delete/107855/useless Del: bad code -- https://master.php.net/note/delete/107855/bad+code Del: spam -- https://master.php.net/note/delete/107855/spam Del: non-english -- https://master.php.net/note/delete/107855/non-english Del: in docs -- https://master.php.net/note/delete/107855/in+docs Del: other reasons-- https://master.php.net/note/delete/107855 Reject -- https://master.php.net/note/reject/107855 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186572) next »