During development, there are many times when a request is made to the database, in which the returned data comes in array, sometimes it is necessary to perform a foreach
to adjust this data or even include more data of according to a specific data.
Example:
$dadosUsuario = $this->UsuarioModel->getDados('all');
foreach($dadosUsuario as $k => $dadoUsuario){
$nome = $dadoUsuario['name'];
$lastName = $dadoUsuario['name'];
$fullName = sprintf('%s %s', $name, $lastName);
$dadoUsuario['fullName'] = $fullName;
$dadosUsuario[$k] = $dadoUsuario;
}
Note that it was necessary to reassign the value of $dadosUsuario[$k]
Would you have some way to make this more dynamic?