Skip to content

Commit 661957d

Browse files
committed
add extra examples to destructuring arrays section
1 parent 282c211 commit 661957d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

translations/es-AR.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,41 @@ list($a, $b, $c, $d) = $array; // PHP Warning: Undefined array key 3
489489
// $d = null;
490490
```
491491

492+
También podés intercambiar variables con asignaciones de desestructuración, considerando que tenés variables como:
493+
```php
494+
$a = 'foo';
495+
$b = 'bar';
496+
```
497+
498+
Entonces, si necesitás intercambiar `$a` y `$b` en lugar de usar una variable temporal como esta:
499+
500+
```php
501+
$temp = $a;
502+
$a = $b;
503+
$b = $temp;
504+
505+
// $a = 'bar'
506+
// $b = 'foo'
507+
```
508+
509+
Podés intercambiarlas usando la sintaxis de lista:
510+
511+
```php
512+
list($a, $b) = [$b, $a];
513+
514+
// $a = 'bar'
515+
// $b = 'foo'
516+
```
517+
518+
O desde PHP 7.1, la sintaxis abreviada:
519+
520+
```php
521+
[$a, $b] = [$b, $a];
522+
523+
// $a = 'bar'
524+
// $b = 'foo'
525+
```
526+
492527
#### Matriz asociativa
493528

494529
![php-version-71](https://shields.io/badge/php->=7.1-blue)

0 commit comments

Comments
 (0)