Babita Bhandari Babita Bhandari - 4 months ago 24
MySQL Question

Show database table column names as pascal case

I have create a table in phpmyadmin where i add the column names as first_name,last_name.When i use the command to show column names from table in database it display columns as first_name.I want to display my column names like this First Name.Can you please tell me how to show column names in pascal case.

Answer

This code converts some_text to Some Text:

$before = array('first_name', 'last_name', 'something');

$after = array();
foreach($before as $v){
    $after[] = implode(' ', array_map('ucfirst', explode('_', $v)));
}

Result:

Array
(
    [0] => First Name
    [1] => Last Name
    [2] => Something
)

And another way of doing the same:

// .. foreach ..
$after[] = ucwords(implode(' ', explode('_', $v)));
// code

The output is the same as before.


Note that I don't know how you have those values nor how you are showing them.

Comments