Req #61727 [Opn->Sus]: Extend array assignment operator ('=>')

From: Date: Thu, 18 Nov 2021 15:42:39 +0000
Subject: Req #61727 [Opn->Sus]: Extend array assignment operator ('=>')
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237857@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61727&edit=1 ID: 61727 Updated by: cmb@php.net Reported by: brad at njoe dot com Summary: Extend array assignment operator ('=>') -Status: Open +Status: Suspended Type: Feature/Change Request Package: Arrays related Operating System: N/A PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Such new syntax clearly needs an RFC. Anybody is welcome to pursue the RFC process[1]. For the time being, I suspend this ticket. [1] <https://wiki.php.net/rfc/howto> Previous Comments: ------------------------------------------------------------------------ [2012-04-13 18:54:49] brad at njoe dot com Description: ------------ This feature would allow one to define a value to be used for creating multiple array indexes (think of it as an array "fill" with a tad more flexibility). The "flexibility" is that rather than using a numerical starting index value and a length parameter, this new syntax would set the same value for each value in a 1-dimensional array of scalars (used as keys). This syntax is essentially a more convenient/concise way of doing something like: foreach($array_of_keys as $key) $the_array[$key] = $value_for_keys; with the added bonus that it would work both when defining an entire array or just modifying an existing array. These two use case scenarios are modeled below as Use Case #1 and #2, respectively. Test script: --------------- <?php /* ---------------------- Use Case #1 ---------------------- */ // set/clear appropriate bits at intialization/definition $binary = array( range( 0, 0) => 1, range( 1, 1) => 0, range( 2, 3) => 1, range( 4, 11) => 0, range(12, 15) => 1 ); /* ---------------------- Use Case #2 ---------------------- */ // initialize array representation of 16-bit binary number to 0 $binary = array_fill(0, 16, 0); // set appropriate bits $binary[range( 0, 0)] = 1; $binary[range( 2, 3)] = 1; $binary[range(12, 15)] = 0; ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61727&edit=1

« previous php.bugs (#237857) next »