note 69005 deleted from function.define by bjori

From: Date: Sat, 26 Aug 2006 11:21:14 +0000
Subject: note 69005 deleted from function.define by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-116347@lists.php.net to get a copy of this message
Note Submitter: thomas at tgohome dot com ---- I was looking for a way to store multiple constants without having to call the define() function more times than necessary. So, I came up with this. define_array(); It feeds data from an array, and calls the define function multiple times. A good way to save space and save time. <? /* * define_array(); * Define a set of items from an array. * * Copyright 2006 Thomas Oldbury. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ function define_array($array, $case = false) { foreach($array as $key => $value) { if(!defined($key)) { define($key, $value, $case); } else { trigger_error("Cannot assign $value to $key because it is already defined", E_USER_WARNING); } } } $defines = array( "T_GLOBAL_KEYWORDS" => "...", "T_GLOBAL_DESCRIPTION" => "...", "T_GLOBAL_COPYRIGHT" => "...", "M_SQL_SERVER" => "...", "M_SQL_USERNAME" => "...", "M_SQL_PASSWORD" => "...", "M_SQL_PERSIST" => false ); define_array($defines); ?> Hope this helps someone as it helped me. -tom

« previous php.notes (#116347) next »