-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
  • 166,373
  • 34
  • 252
  • 304
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
  • 166,373
  • 34
  • 252
  • 304