if(!is_array($conf[$name])) $conf[$name] = array($val); else $conf[$name][] = $val;
Cameron B. Prince wrote:
Hey guys,
I'm making progress on my perl to PHP conversion project but I need some help...
I have a configuration table in MySQL made up like this:
CREATE TABLE config ( code mediumint(9) NOT NULL auto_increment, site varchar(32) NOT NULL default '', name varchar(64) NOT NULL default '', value varchar(128) NOT NULL default '', seq smallint(4) default NULL, PRIMARY KEY (code) ) TYPE=MyISAM;
It has data like this:
| 1 | site1 | homedir | /var/www/htdocs/site1 | NULL | | 2 | site1 | groupname | Group1 | 1 | | 3 | site1 | groupname | Group2 | 2 |
I use this query to get the configuration data:
SELECT name, value FROM config WHERE site = '$site' ORDER BY name, seq
What I want to create is an array of arrays like this:
$conf[$name][] = $val;
or
array_push($conf[$name], $val);
So I end up with something like:
$conf[homedir][0] = /var/www/htdocs/site1 $conf[groupname][0] = Group1 $conf[groupname][1] = Group2
If I were still in Perl-land, I'd use a hash of arrays and push things into it, but I don't seem to have that option now and I keep getting "Use of undefined constant name" errors.
Am I going about this in the right way? Any help would be greatly appreciated.
Thanks, Cameron
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php