I have an array of people from which I want the first letter of each word to become capital, so I am using ucwords()
. The problem arises since you are acting as if you are using ucfirst()
.
Code:
foreach ($data['alumnos'] as &$alumno) {
var_dump($alumno['nombre_completo']);
$alumno['nombre_completo'] = ucwords(strtolower($alumno['nombre_completo']));
var_dump($alumno['nombre_completo']);
}
Exit:
string(29) "BARRIOS HERNANDEZ CHRISTIAN"
string(29) "Barrios hernandez christian"
string(32) "CASTAÑEDA PADILLA JUAN DIEGO"
string(32) "CastaÑeda padilla juan diego"
string(31) "CORONA VALADEZ CARLOS ALEXIS"
string(31) "Corona valadez carlos alexis"
string(31) "DE REZA VELEZ JESUS OSWALDO"
string(31) "De reza velez jesus oswaldo"
string(34) "ALTAMIRANO MORELOS DAN EMMANUEL"
string(34) "Altamirano morelos dan emmanuel"
string(34) "ALVARADO CONTRERAS JORGE CARLOS"
string(34) "Alvarado contreras jorge carlos"
Only convert the first letter as if it were ucfirst()
. In which part I am implementing it in the wrong way or where the problem arises.
It works well for me when I do it directly in a one-person arrangement.
Example:
$data['profesor']['nombre_completo'] = ucwords(strtolower($data['profesor']['nombre_completo']));