Re: Bug #13846 Updated: Patch: Use [ ] as shortcut forarray()
| From: | Zakaria | Date: | Sun, 28 Oct 2001 00:19:27 +0000 |
| Subject: | Re: Bug #13846 Updated: Patch: Use [ ] as shortcut forarray() | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-69160@lists.php.net to get a copy of this message | ||
Assalamu'alaikum wr. wb.
Derick Rethans wrote:
> Hello,
> I would say -1 on this, this is not readable and IMHO just a hack:
> $array = [['9', 34],[7],[1,'string']];
And this is a lot better?
$array = array(array('9', 34),array(7),array(1, 'string'));
IMHO the array() only making line noise instead revealing the intent.
Consider more complex use of array.
$param = array(table => 'emp'
, fields => array(
id => array(datatype => INT, pk => true)
, name => array(datatype => STRING, unique => true
, not_null => true)
, dept_id => array(datatype => INT, not_null => true
, fk => array(table => 'dept', field => 'dept_id')
)
)
);
with
$param = [table => 'emp'
, fields => [
id => [datatype => INT, pk => true]
, name => [datatype => STRING, unique => true, not_null
=> true]
, dept_id => [datatype => INT, not_null => true
, fk => [table => 'dept', field => 'dept_id']
]
]
]
And the use of array as named parameter
db(array(name => 'comic', user => 'web', password =>
's3cret!'));
with
db([name => 'comic', user => 'web', password => 's3cret!']);
and if that's not enough consider that in other scripting languange
array constant is expressed in less character than PHP.
For example:
Perl: $list = (1, 2 ,3, 'four', 'five', (6.1, 6.2, 6.3));
Python: list = [1, 2, 3, 'four', 'five', [6.1, 6.2, 6.3]]
Ruby: list = [1, 2, 3, 'four', 'five', [6.1, 6.2, 6.3]]
Tcl: set list {1 2 3 four five {6.1 6.2 6.3}}
PHP: $list = array(1, 2, 3, 'four', 'five', array(6.1, 6.2, 6.3));
> regrads,
> Derick
> Derick Rethans
Wassallam,
-- Zakaria
Work: zakaria@asia-karsa.com, http://asia-karsa.com
Private: z4k4ri4@bigfoot.com Yahoo!: z4k4ri4
http://pemula.linux.or.id