-3

i have this array:

Array
(
    [name] => jim ross
    [address] => colorado
    [occupation] => actor
)

i will use the following code to get the data from the form

if(isset($_POST['submit'])) { 
    $values = $_POST['details'];
}

here $values contains the name, address and occupation

Now I want to insert it into database by capitalizing each words, but ucwords() doesn't apply to arrays. How can I apply it to every element in my array?

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
rt8s
  • 1
  • 2

1 Answers1

2

To apply a function to every element in your array, you can use array_map()

$values = array_map('ucwords', $_POST['details']);
// each element in $values has had ucwords() applied to it
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
  • thanks buddy for understanding what i wanted to do :D – rt8s Dec 02 '13 at 10:02
  • @rt8s You should not be using `mysql_` functions any more, but it can be applied in the same manner. – Ja͢ck Dec 02 '13 at 10:06
  • as i am new to php would you please tell me why i should not use mysql_ functions any more........i have been taught to do so :( – rt8s Dec 02 '13 at 10:07
  • @rt8s See [this question](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) for more answers. – Ja͢ck Dec 02 '13 at 10:25