Jump to content

Recommended Posts

This doesnt work for some reason

 

 

//Directory To You Style

$config[theme] ='default';

 

//Style Initialization

$config        ='./theme/$config[theme]/html.php';

$config[html2] ='./theme/$config[theme]/html2.php';

include("./theme/$config[theme]/styleinfo.php");

Link to comment
https://forums.phpfreaks.com/topic/73224-solved-noobie-variable-defining-question/
Share on other sites

shouldn't make a difference, but put inverted commas round the bracketed arrays:

 

//Directory To You Style

$config['theme']      ='default';

 

//Style Initialization

$config      ='./theme/$config[theme]/html.php';

$config['html2']      ='./theme/$config[theme]/html2.php';

include("./theme/$config[theme]/styleinfo.php");

Try:

 

<?php
$config['theme']='default';
//Style Initialization
$config['html']='./theme/'.$config['theme'].'/html.php';
$config['html2']='./theme/'.$config['theme'].'/html2.php';
include('./theme/'.$config['theme'].'/styleinfo.php');
?>

 

You should quote array keys which are strings - otherwise you will recieve an undefined constant notice if you have error reporting set to include notices.

 

Second, in your previous code you defined $config as an array (implicitly by using the key, 'them'), then changed it to a string, since you gave no key in this line: $config      ='./theme/$config[theme]/html.php';

You then change it back to an array in the following line. The end result: an array with only one element.

 

Lastly, strings inside single quotes are treated as literals. The following code:

<?php
$foo = 'bar';
echo '$foo';
?>

Produces the text: $foo - not the variables contents, bar.

 

When echoing a variable, you either use concatenation(as i did - using the . to 'piece together' the bits of your string), or use double quotes.

 

Your problem is understanding the difference between a string and an array:

 

//Directory To You Style
$config[theme]      ='default';

//Style Initialization
$config           ='./theme/$config[theme]/html.php';
$config[html2]      ='./theme/$config[theme]/html2.php';
include("./theme/$config[theme]/styleinfo.php");

 

First, define $config as an array initially to deal with annoying php.ini files.

Second, $config[theme] needs to have quotes around "theme" or else PHP will interpret that as another variable/undefined constant. So:

 

$config = array();
$config['theme'] = 'default';

 

This part is fine. This means $config is defined as an array and that the index 'theme' is defined as 'default'.

 

Now, look at your second part of the code:

 

//Style Initialization
$config           ='./theme/$config[theme]/html.php';
$config[html2]      ='./theme/$config[theme]/html2.php';
include("./theme/$config[theme]/styleinfo.php");

 

You want to store a string into a variable already defined as an array, this is a 'no-no'. Define another index of $config in order to make it work, IE $config['html']. Also put double quotes around the whole thing so it can be added into the thing correctly.

 

//Style Initialization
$config['html'] = "./theme/".$config['theme']."/html.php";
$config['html2'] = "./theme/".$config['theme']."/html2.php";
include("./theme/".$config['theme']."/styleinfo.php");

 

Finished code:

 

$config = array();
$config['theme'] = 'default';

//Style Initialization
$config['html'] = "./theme/".$config['theme']."/html.php";
$config['html2'] = "./theme/".$config['theme']."/html2.php";
include("./theme/".$config['theme']."/styleinfo.php");

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.