Airikr
Airikr

Reputation: 6436

Make all the strings of a string array into lower case except for the first word

Supposing I have an array Tomat, Ost How can I accomplish so it is like this: Tomat, ost?

$ingredient_a = Array('Tomat', 'Ost');
echo implode(', ', $ingredient_a);

Upvotes: 0

Views: 389

Answers (2)

roric32
roric32

Reputation: 31

$ingredient_a = array('Tomat', 'Ost');
$new = array();

foreach($ingredient_a as $key => $value) {
    $key == 0 ? $new[] = $value : $new[] = strtolower($value);
}

echo implode(', ', $new);

Upvotes: 0

JOUM
JOUM

Reputation: 254

Use ucfirst and array_map with strtolower

echo ucfirst(implode(', ', array_map('strtolower',$ingredient_a)));

Upvotes: 5

Related Questions