I have a string like so:
Quaint village location, seaside views, four bedrooms
I need to do the following:
- Take each comma separated item and add it into an array
- Remove whitespace from beginning and end
- Capitalise the first letter
So for example, the above string becomes:
array(
[0] => 'Quaint village location',
[1] => 'Seaside views',
[2] => 'Four bedrooms',
)
I have started this code block using trim
, explode
and ucfirst
but I don't think I'm going about it a very efficient way.
iif(get_field('property_information') != NULL){
$raw_facilities_list = explode(",", get_field('property_information'));
$other_facilities_list = [];
foreach($raw_facilities_list as $facility){
$facility = trim($facility);
$facility = ucfirst($facility);
array_push($other_facilities_list,$facility);
}
$property['extra_features'] = $other_facilities_list;
echo '<pre>';
var_dump($property);
echo '</pre>';
}
What is the most efficient way to perform these 3 tasks?