Jump to content

[SOLVED] Exluding certain elements of array...


Aureole

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.