|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-02-10 14:15 UTC] jimw@php.net
[2003-07-17 16:15 UTC] tomer at parity-bit dot com
[2006-04-03 09:28 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 11:00:01 2025 UTC |
To my knowledge there's no way of labelling/declaring the keys in an associative arrays once and then simply only specifying the individual values. So when I set up an array with basically constant string values I ended up typing something like this 75 times: $tokens[] = array ( "startcode" => "la", "endcode" => "di", "classname" => "da" ); $tokens[] = array ( "startcode" => "ob", "endcode" => "la", "classname" => "di" ); etc. So an extension to the array() definition would greatly be appreciated to alleviate the typing. I suggest something like: array ( [keylist][keylist][keylist] = val1, val2, val3, etc, ); or in the above example array ( [][keylist] = ) Where 'keylist' is a finite list of keys of the associative array and '[]' denotes the current behaviour of defaulting to numeric keys starting at 'number of element in array =1' Example: $tokens = array ( ['foo', 'bar']['start','end','class'] = "la", "di", "da", // the elements of 'foo' "ob", "la", "di" // ditto 'bar' ); Which gives $tokens['foo']['start']="la", $tokens['foo']['end']="di", $tokens['foo']['class']="da" $tokens['bar']['class']= "ob", $tokens['bar']['class']= "la", $tokens['bar']['class']= "di". Similar: $tokens = array( []['start,'end',class'] = "la", "di","da", "ob", "la", "di" ); gives $tokens[0]['start']="la" etc. until $tokens[1]['class']="di" (assuming $tokens was empty) Possible extensions for numeric keys may be: '[1..3]' denoting a finite list with numeric keys starting with 1 and ending with 3 inclusive. In this case, if less than 3 rows are subsequently defined, row3 would still exist but be empty and '[5..]' denoting 'start at numeric key 5 and count upwards' Basically it all boils down to the inability to specify an associative key-name for a specific index position - a kind of a reverse 'key()' function. (Yes indeed that's the second feature request in the same report;-)) Can't say that I've succeeded in limiting the typing this time, but I hope you can do something with these suggestions. Thanks and keep up the excellent work! Erwin van Dongen