From: Operating system: N/A PHP version: Irrelevant Package: Arrays related Bug Type: Feature/Change Request Bug description:Extend array assignment operator ('=>')
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 bug report at https://bugs.php.net/bug.php?id=61727&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61727&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61727&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61727&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61727&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61727&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61727&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61727&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61727&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61727&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61727&r=support Expected behavior: https://bugs.php.net/fix.php?id=61727&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61727&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61727&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61727&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61727&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61727&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61727&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61727&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61727&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61727&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61727&r=mysqlcfg