Jump to content

[SOLVED] creating a var problem.


xyn

Recommended Posts

hey guys.

Basically i've got a class. but im having a problem setting class vars

using an array... i get a T_VAR error when using $this->$name.

 

my current code is...

Page 1.php

$template = new Class;
$array =array(
  'name' => 'value',
  'name_b' => 'value_2'
);
$template->set_vars($array);

 

and my class is :

class Class {
function assign_vars($array){
	foreach($array as $name => $value){
		return $this->$name = $value;
	}
}
}

Link to comment
https://forums.phpfreaks.com/topic/77829-solved-creating-a-var-problem/
Share on other sites

yer i know..

but the $name comes from the array  foreach($array as $name => $value){

 

anyway, ive decuded to use this...

function assign_varname($str){  return $this->varname = $str;

which varname will be changed to what the name actually is... I

was initially hopeing to be able to use an array.

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.