Aureole Posted February 4, 2008 Share Posted February 4, 2008 I'm not going to post all the code from the files, just the code which is relevant, I'll remove the rest.. dump_vars() should only dump all the vars that don't begin with "db", but it's showing all of them, any ideas? Here is conf.php: <?php $vars['db_host'] = 'localhost'; $vars['db_database'] = '***'; $vars['db_user'] = '***'; $vars['db_pass'] = '***'; $vars['start_timestamp'] = ''; $vars['installed'] = '1'; $vars['php_ext'] = 'php'; $vars['board_url'] = 'http://www.mywebsite.com/folder/index.' . $vars['php_ext']; $vars['root_group'] = '1'; $vars['admin_group'] = '2'; $vars['member_group'] = '3'; $vars['banned_group'] = '4'; ?> Here's class_equinox.php: <?php /** /----------------------------------- / Equinox /=================================== / @author: .KX / @date: 03 February 2008, 22:42 GMT / @revision: 1 /=================================== / @file: Equinox Class / @started: 03 February 2008 / @updated: /----------------------------------- */ class equinox { /** * Variables from conf.php * @var [array] */ var $vars; //----------------------------------------- // Dump vars from conf.php for debugging // purposes. //----------------------------------------- function dump_vars() { foreach($this->vars as $key => $val) { // Exclude database stuff from dump, we don't want anyone accidentally giving away their database details... if( $key !== 'db_host' || 'db_user' || 'db_pass' || 'db_database' ) { echo( "<strong>$key:</strong> $val<br>\n" ); } } } } ?> ...and here's index.php <?php /** /----------------------------------- / Equinox /=================================== / @author: .KX / @date: 04 February 2008, 12:26 GMT / @revision: 1 /=================================== / @file: Equinox Wrapper / @started: 04 February 2008 / @updated: /----------------------------------- */ //-------------------------------- // Load Classes etc. //-------------------------------- require_once( 'init.php' ); $vars = array(); require_once( ROOT_PATH . 'conf.php' ); require_once( ROOT_PATH . 'classes/class_equinox.php' ); //-------------------------------- // Instantiation for the nation //-------------------------------- $equinox = new equinox; $equinox->vars = $vars; $equinox->initialize(); $equinox->initialize_db_connection(); $equinox->dump_vars(); ?> Link to comment https://forums.phpfreaks.com/topic/89358-solved-exluding-certain-elements-of-array/ Share on other sites More sharing options...
trq Posted February 4, 2008 Share Posted February 4, 2008 Your way... <?php function dump_vars() { foreach($this->vars as $key => $val) { // Exclude database stuff from dump, we don't want anyone accidentally giving away their database details... if ( $key !== 'db_host' || $key !== 'db_user' || $key !== 'db_pass' || $key !== 'db_database' ) { echo( "<strong>$key:</strong> $val<br>\n" ); } } } ?> My way... <?php function dump_vars() { foreach($this->vars as $key => $val) { // Exclude database stuff from dump, we don't want anyone accidentally giving away their database details... if (substr($key,0,2) !== 'db') { echo( "<strong>$key:</strong> $val<br>\n" ); } } } Link to comment https://forums.phpfreaks.com/topic/89358-solved-exluding-certain-elements-of-array/#findComment-457581 Share on other sites More sharing options...
Aureole Posted February 4, 2008 Author Share Posted February 4, 2008 Very nice, thanks again. Link to comment https://forums.phpfreaks.com/topic/89358-solved-exluding-certain-elements-of-array/#findComment-457587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.