note 93997 deleted from function.array by salathe
| From: | salathe@php.net | Date: | Fri, 22 Jun 2012 21:53:23 +0000 |
| Subject: | note 93997 deleted from function.array by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188764@lists.php.net to get a copy of this message | ||
Note Submitter: mail at leonardomartinez dot com
----
<?php
function array_two_key_swap( $multidimensional_array ) {
/*
Writen by: Leonardo Martinez
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;
}
?>