Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A more "hair friendly" way to modify an array from within a foreach loop is to just use the array key:

    foreach($array as $key => $value)
    {
        if(someCondition($key))
            $array[$key] = someTransformation($value);
    }
or whatever - ie. just use the key to modify the original array directly. It's much easier to read and see what's happening (in my opinion anyway).


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: