Skip to content

Instantly share code, notes, and snippets.

@DennisRas
Created October 25, 2011 18:23
Show Gist options
  • Save DennisRas/1313736 to your computer and use it in GitHub Desktop.
Save DennisRas/1313736 to your computer and use it in GitHub Desktop.
Convert assoc values from alpha to numeric position of the alhapbet
<?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