ID: 3928
Updated by: jimw
Reported By: [EMAIL PROTECTED]
Status: Open
Bug Type: Feature/Change Request
Assigned To:
Comments:
refiling against 4.0.
Previous Comments:
---------------------------------------------------------------------------
[2000-03-26 02:11:31] [EMAIL PROTECTED]
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
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=3928&edit=2
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]