note 93997 added to function.array
| From: | mail at leonardomartinez dot com | Date: | Sat, 10 Oct 2009 20:39:09 +0000 |
| Subject: | note 93997 added to function.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161624@lists.php.net to get a copy of this message | ||
function array_two_key_swap( $multidimensional_array ) {
/*
Writen by: Leonardo Martinez
Contact: http://www.leonardomartinez.com/contact/
Created: 10-10-2009
Modified: 10-15-2009
This function takes a two dimensional array[x][y], swaps the first
key with the second key so the values can be referenced using array[y][x].
Example:
samplearray['directiory'][0] = "myicons";
samplearray['directiory'][1] = "myicons";
samplearray['directiory'][2] = "myiconsold";
samplearray['directiory'][3] = "myiconsold";
samplearray['filename'][0] = "hat.png";
samplearray['filename'][1] = "dog.png";
samplearray['filename'][2] = "mice.png";
samplearray['filename'][3] = "rat.png";
The above array converts to:
newarray[0]['filename'] = "hat.png"
newarray[0]['directiory'] = "myicons"
newarray[1]['filename'] = "dog.png"
newarray[1]['directiory'] = "myicons"
newarray[2]['filename'] = "mice.png"
newarray[2]['directiory'] = "myiconsold"
newarray[3]['filename'] = "rat.png"
newarray[3]['directiory'] = "myiconsold"
*/
$keys = array_keys( $multidimensional_array );
$array_swaped = array();
foreach($multidimensional_array[$keys[0]] as $key_counter => $value1) {
$temp_array = array();
foreach($keys as $key) {
$temp_array[$key] = $multidimensional_array[$key][$key_counter];
}
$array_swaped[] = $temp_array;
}
return $array_swaped;
}
----
Server IP: 208.69.120.35
Probable Submitter: 98.26.72.53
----
Manual Page -- http://www.php.net/manual/en/function.array.php
Edit -- https://master.php.net/note/edit/93997
Del: integrated -- https://master.php.net/note/delete/93997/integrated
Del: useless -- https://master.php.net/note/delete/93997/useless
Del: bad code -- https://master.php.net/note/delete/93997/bad+code
Del: spam -- https://master.php.net/note/delete/93997/spam
Del: non-english -- https://master.php.net/note/delete/93997/non-english
Del: in docs -- https://master.php.net/note/delete/93997/in+docs
Del: other reasons-- https://master.php.net/note/delete/93997
Reject -- https://master.php.net/note/reject/93997
Search -- https://master.php.net/manage/user-notes.php