rfc:additional-splat-usage
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:additional-splat-usage [2017/09/06 02:56] – Additional info and revive this RFC! haskellcamargo | rfc:additional-splat-usage [2021/06/09 16:03] (current) – Status set to inactive for consistency, it was already part of the "Inactive" list patrickallaert | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2014-11-03 | * Date: 2014-11-03 | ||
* Author: Chris Wright, daverandom@php.net, | * Author: Chris Wright, daverandom@php.net, | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 33: | Line 33: | ||
The new syntax gives equivalent behaviour to the '' | The new syntax gives equivalent behaviour to the '' | ||
- | As such, the following | + | As such, the following |
<code php> | <code php> | ||
- | <?php | ||
$array1 = [" | $array1 = [" | ||
$array2 = [" | $array2 = [" | ||
Line 41: | Line 40: | ||
$result = array_merge($array1, | $result = array_merge($array1, | ||
$result2 = [...$array1, | $result2 = [...$array1, | ||
- | ?> | ||
</ | </ | ||
- | Combinations | + | A mixture |
<code php> | <code php> | ||
- | <?php | ||
$array1 = [" | $array1 = [" | ||
$array2 = [" | $array2 = [" | ||
Line 52: | Line 49: | ||
$result = array_merge($array1, | $result = array_merge($array1, | ||
$result2 = [...$array1, | $result2 = [...$array1, | ||
- | ?> | ||
</ | </ | ||
+ | |||
+ | The operator should have the same behaviour for numeric and associative arrays. | ||
+ | Multidimensional arrays should not be flattened: the splat operator should have effect in the first level keys only. | ||
+ | |||
+ | === Numeric === | ||
+ | |||
+ | <code php> | ||
+ | $threetofive = [3,4,5]; | ||
+ | $zerotofive = [0, 1, 2, ...$threetofive]; | ||
+ | </ | ||
+ | |||
+ | === Associative === | ||
+ | |||
+ | <code php> | ||
+ | $addressData = [" | ||
+ | $cityData = [" | ||
+ | |||
+ | $propertyData = [" | ||
+ | </ | ||
+ | |||
+ | === Multidimensional === | ||
+ | |||
+ | <code php> | ||
+ | $old_marks = [ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | ]; | ||
+ | |||
+ | $new_marks = [ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | ...$old_marks | ||
+ | ]; /* array(4) { [" | ||
+ | </ | ||
+ | |||
Using the splat operator with elements that are not arrays and not '' | Using the splat operator with elements that are not arrays and not '' | ||
Line 107: | Line 150: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
- |
rfc/additional-splat-usage.1504666613.txt.gz · Last modified: 2017/09/22 13:28 (external edit)