Skip to content

Instantly share code, notes, and snippets.

@alvaro-prieto
Last active November 9, 2023 12:06
Show Gist options
  • Save alvaro-prieto/041ab2fa810218396be2ad13e2db22ea to your computer and use it in GitHub Desktop.
Save alvaro-prieto/041ab2fa810218396be2ad13e2db22ea to your computer and use it in GitHub Desktop.
# Foreach en php
## Si queremos modificar o agregar un campo de un array preexistente
```php
//Agregamos una nueva columna sin hacer copias del objeto, modificándolo directamente
foreach ($datos as &$elemento) {
$elemento['url'] = "<a href='" . $elemento['enlace'] . "'>" . $elemento['entidad'] . "</a>";
}
unset($elemento);
//por seguridad, par evitar que se cambie algo sin querer
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment