Paradigm Shift Design

ISHITOYA Kentaro's blog.

アンダーラインを含む変数名をキャメルネームにする

lower_camel_nameをlowerCamelNameに変換する関数。

<?php
function convertToCamelName($propertyName){
    $function = create_function('$matches', 'return strtoupper($matches[1]);');
    return preg_replace_callback('/_([a-z])/', $function, $propertyName);
}
?>

preg_replace_callbackとcreate_functionはこういうときに使うらしい。