Created
October 25, 2011 18:23
-
-
Save DennisRas/1313736 to your computer and use it in GitHub Desktop.
Convert assoc values from alpha to numeric position of the alhapbet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array('hi' => 'a', 'yo' => 'b'); | |
array_walk($array, function(&$value, $key){ | |
$value = strpos('abcdefghijklmnopqrstuvwxyz', $value) + 1; | |
}); | |
print_r($array); // Array ( [hi] => 1 [yo] => 2 ) | |
// < PHP 5.3 | |
function alphanum(&$value, $key){ | |
$value = strpos('abcdefghijklmnopqrstuvwxyz', $value) + 1; | |
} | |
$array = array('hi' => 'a', 'yo' => 'b'); | |
array_walk($array, 'alphanum'); | |
print_r($array); // Array ( [hi] => 1 [yo] => 2 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment