PHP Laravel Convert array value to upper case
The Str::upper
method converts the given string to uppercase:
use Illuminate\Support\Str;
$string = Str::upper('laravel');
If you're getting data from DB by using Eloquent, you could create an accessor
public function getProvince($value)
{
return strtoupper($value);
}
If not, you could change it manually:
for ($i = 0; $i < count($data); $i++) {
$data[$i]['province'] = strtoupper($data[$i]['province']);
}
$collection
is the array of objects, then try to use this way :
$collection = collect($array);
$keyed = $collection->keyBy(function ($item) {
return strtoupper($item['province']);
});
$keyed->all();