Quote Originally Posted by SplitIce View Post
Oh noes totally going to get banned for this (sarcasm). I guess there may be a reason you didnt use array_map (part of a larger function) but for the benefit of the thread readers.

PHP Code: 
array_map(function($v) {
        return 
parse_url(preg_match('#^http://#si'$v) ? $v 'http://' $v);
    },
$a); 
Just a quick explanation of the changes since they are minor:
  1. preg match 's' flag optimizes the expression (good when it needs to be used multiple times)
  2. preg_match 'i' flag for case insensitivity
  3. array_map not array_walk for mapping values (no reference)


Also just note the parameter order switch, an example of the inconsistencies in PHP.

EDIT 4:
Actually on second thoughts if you wanted to be pedantic:
PHP Code: 
function($v) {
    return 
parse_url(substr_compare($v'http://'07) ? 'http://' $v $v);

Although thats taking it too far right? Still I dont think anyone could do it more efficiently (a challenge).
Here:
- No, 's' does not make it more efficient, it makes the dot character ('.') include newlines, the default is to exclude newlines
- Case insensitivity was not needed in my code, it was passed through strtolower beforehand (paths were irrelevant for my usage, so loss of case did not matter)
- array_walk because I wanted to change the array in place, not allocate memory for a copy of the array and change that instead.

Doing it more efficiently... well the fact that I used array_walk to change the same array in-place likely outperforms your suggested alternative already. I am not creating any new variables, rather changing the same ones in memory, one by one.

As for the guy above using regex, use (\d+) not (.*).