I have an array, I want its value to be "public $ somevariable". Here is my function of how it looks.
public function __construct(){
global $database;
$result = $database->query("SHOW COLUMNS FROM ".self::$tabel_name."");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
if (mysql_num_rows($result) > 0) {
$attributes_var = array();
while ($row = $database->fetch_array($result)) {
$attributes_var[] = $row[0];
}
}
foreach($attributes_var as $key)
{
public $$key;
}
}
But a syntax error is shown on "public $$ key". I want to use a dynamic generated variable as a public variable and want to use it outside the class.
Any suggestion?
Thank!
source
share