phpucfirst

ucfirst after comma separated value


I have the value like admin,bli

I have used this code to make the first letter capital

<?php ucfirst('admin,bli'); ?>

And my result is Admin,bli

My expected output is

Admin,Bli

How can I achieve this without using explode function and a for loop?


Solution

  • <?php
        echo join(',', array_map('ucfirst', explode(',', 'bill,jim')));
    ?>
    

    Explode by comma, map ucfirst every item using array_map and implode it back by join or implode.

    I know you'd like to avoid explode, but its probably quicker than preg_replace_callback anyway.