rfc:array_part

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:array_part [2012/05/21 21:03] – no references cataphractrfc:array_part [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2012-05-14   * Date: 2012-05-14
   * Author: Gustavo Lopes <cataphract@php.net>   * Author: Gustavo Lopes <cataphract@php.net>
-  * Status: Under Discussion+  * Status: Declined
   * First Published at: http://wiki.php.net/rfc/array_part   * First Published at: http://wiki.php.net/rfc/array_part
  
Line 25: Line 25:
 Each part specification shall have one of the following forms: Each part specification shall have one of the following forms:
  
-  * A sequential numeric array of indexes, which specifies that only the elements existing at those indexes will be kept.+  * A non-empty sequential numeric array of indexes, which specifies that only the elements existing at those indexes will be kept.
   * A single index, which specifies that only the element existing at that index will be kept. In this case the level will be collapsed onto the previous one, meaning all the arrays at that level will be replaced with its element the specified index.   * A single index, which specifies that only the element existing at that index will be kept. In this case the level will be collapsed onto the previous one, meaning all the arrays at that level will be replaced with its element the specified index.
   * A span part specification is an associative array. The following keys are allowed //start//, //end// and //step//. At least //start// or //end// must be specified. //start// and //end// are an index or a special value -- ''null''. //step// is a non-zero integer, defaulting to ''1''. If ''start'' or ''end'' are not specified, they default to ''null'', which refer to either the first or last element depending on the sign of //step//. If //step// is +-1 and //start// and //end// are both ''null'' (or, if ''$indexesAreKeys'' is ''false'', //start// and //end// are //0// and //-1// or vice-versa depending on the sign of //step//), then we say the span encompasses all elements on that level (possibly 0).   * A span part specification is an associative array. The following keys are allowed //start//, //end// and //step//. At least //start// or //end// must be specified. //start// and //end// are an index or a special value -- ''null''. //step// is a non-zero integer, defaulting to ''1''. If ''start'' or ''end'' are not specified, they default to ''null'', which refer to either the first or last element depending on the sign of //step//. If //step// is +-1 and //start// and //end// are both ''null'' (or, if ''$indexesAreKeys'' is ''false'', //start// and //end// are //0// and //-1// or vice-versa depending on the sign of //step//), then we say the span encompasses all elements on that level (possibly 0).
Line 78: Line 78:
  
 This is true. We must traverse the array from the start or the end to get to the n-th element. That's just the way PHP arrays are implemented. However, if you have numeric sequential arrays, you can use ''$indexesAreKeys = true'' to access the n-th element without this penalty (also note that the sample implementation is **not** optimized). This is true. We must traverse the array from the start or the end to get to the n-th element. That's just the way PHP arrays are implemented. However, if you have numeric sequential arrays, you can use ''$indexesAreKeys = true'' to access the n-th element without this penalty (also note that the sample implementation is **not** optimized).
 +
 +===== Vote =====
 +
 +<doodle 
 +title="Should the current array_part() implementation be merged" auth="cataphract" voteType="single" closed="False">
 +   * Yes
 +   * No
 +</doodle>
  
 ===== Changelog ===== ===== Changelog =====
Line 84: Line 92:
   * 2012-05-21 Dropped recursion restriction, added note on how references are preserved, added link to native implementation   * 2012-05-21 Dropped recursion restriction, added note on how references are preserved, added link to native implementation
   * 2012-05-21 References are not preserved after all   * 2012-05-21 References are not preserved after all
 +  * 2012-05-28 Vote opened
  
rfc/array_part.1337634232.txt.gz · Last modified: 2017/09/22 13:28 (external edit)