note 59252 added to function.define

From: Date: Wed, 30 Nov 2005 18:46:12 +0000
Subject: note 59252 added to function.define
Groups: php.notes 
Request: Send a blank email to php-notes+get-99375@lists.php.net to get a copy of this message
My hack at constant arrays : function carray($const = null, $index = null) { static $carrays; if ($const === null) { $i = count($carrays); $carrays[$i] = $index; return $i; } else { return $index === null ? $carrays[$const] : $carrays[$const][$index]; } } function aconst() { $args = func_get_args(); if (count($args) == 1 && is_array($args[0])) { return carray(null, $args[0]); } else { return carray(null, $args); } } Use like this: define('NRWORDS', aconst('zero', 'one', 'two', 'three')); define('STUNT_DESC', aconst(array( STUNT_TWOWHEELS => 'Two wheels', STUNT_WHEELIE => 'Wheelie', STUNT_STOPPIE => 'Stoppie' ))); print(carray(NRWORDS, 2)); print(carray(STUNT_DESC, STUNT_WHEELIE)); $arr = carray(STUNT_DESC); print_r($arr[STUNT_STOPPIE]); bvr. ---- Manual Page -- http://www.php.net/manual/en/function.define.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59252 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59252&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59252&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59252&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59252&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59252&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59252&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59252&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59252&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#99375) next »