Jump to content

Create a variable from array value.


Domcsore

Recommended Posts

I currently have this:

$engineSuffix = '.global_conf.php';
	$objSuffix = '_conf';

	$engine[0] = 'template';
	$engine[1] = 'admin';

	$engineCount = count($engine);

	$e = 0;

	while ($e<$engineCount){
		include_once($engine[$e].$engineSuffix);
		$e++;

	}

 

but I would like something like this:

$engineSuffix = '.global_conf.php';
	$objSuffix = '_conf';

	$engine[0] = 'template';
	$engine[1] = 'admin';

	$engineCount = count($engine);

	$e = 0;

	while ($e<$engineCount){
		include_once($engine[$e].$engineSuffix);
		$e++;

                        $'VALUE OF ARRAY $engine[$e] AND VALUE OF $objSuffix AS VARIABLE NAME' = new $engine[$e];

	}

 

Is there a way to do this?

 

 

Link to comment
https://forums.phpfreaks.com/topic/198855-create-a-variable-from-array-value/
Share on other sites

Basically what I am trying to do is load extend classes from a separate file, however I just want the files to include and create a new object automatically from the array name given. For example my template class would be like so:

 

file name: template.global_conf.php

 

that would be a template class which is an extend of my global_conf class.

 

so in my global_conf class __construct function I have it so it includes the files automatically as shown above however I have issues trying to create the template object in the loop.

 

(Should have really explained my objective to start, sorry)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.