I have an array with multiples values in my Laravel project:
array:1434 [▼
  0 => array:53 [▼
    "contact" => "ANA (dependienta)"
    "mail" => "[email protected]"
    "phone2" => ""
    "phone3" => ""
    "web" => "0"
    "active" => true
    "province" => "Zaragoza"
  ]
  1 => array:53 [▼
    "contact" => "JACKELINE * VIVIANA"
    "mail" => "[email protected]"
    "phone2" => ""
    "phone3" => ""
    "web" => "0"
    "active" => true
    "province" => "Barcelona"
  ]
I want transform to upper case only the province value, I want to get this result:
array:1434 [▼
  0 => array:53 [▼
    "contact" => "ANA (dependienta)"
    "mail" => "[email protected]"
    "phone2" => ""
    "phone3" => ""
    "web" => "0"
    "active" => true
    "province" => "ZARAGOZA"
  ]
  1 => array:53 [▼
    "contact" => "JACKELINE * VIVIANA"
    "mail" => "[email protected]"
    "phone2" => ""
    "phone3" => ""
    "web" => "0"
    "active" => true
    "province" => "BARCELONA"
  ]
Exists any method or way to make this with Laravel Collection or other alternatives?
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();
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With