如何将数组的首字母大写值转换为小写

I have a form

Name : i.e in form (name = "detail[name]")

Address : i.e in form (name = "detail[address]")

Email : i.e in form (name = "detail[email]")

I fetched the data as follows in php:

$data = array_map('ucwords', $_POST['detail']);

I got all the values with capitalized first letter in my database after using insert query

Then I have realized that email should not be in caps so I thought of converting it to lowercase while making sure other values remains constant

And I failed ... so anyone interested to help me is most welcomed :D

Thanks in advance

Simple: PHP's strtolower function.

$lower = strtolower($value)

you can use a foreach to make the changes of all your posted values like

  $detail = $_POST['detail'];
  $arr = array();
  foreach($detail as $key => $value){

       if($key != 'email'){
           $arr[$key] = ucword($value);
        } else {
           $arr[$key] = $value;
        }

  }

Now what will happen is you will get a new array $arr which you can store directly into your databse which dont have email with first letter CAPS

You can use this function to obtain first letter in small:

$email = strtolower($email);

Why do you use ucwords then ?

$data = array_map('ucwords', $_POST['detail']);

That will make your contents inside the $_POST['detail'] to be in UPPER case. Just don't use it.

Remove the array_map and ucwords and just do like this.

$data =  $_POST['detail'];
$email = strtolower($email);

Its very simple.But u are saying its dynamic can u please elaborate or paste your code.

If you want to convert the whole word to lowercase then just use:

$oldString = "Something";
$newString = $strtolower($oldString);

Otherwise if you want to strictly convert only the first letter you can use:

$oldString = "SOMETHING";
$newString = $strtolower($substr($oldString, 0, 1)) . $substr($oldString, 1);