How do i dynamically assign a name to a php object?
for example how would i assign a object to a var that is the id of the db row that i am using to create objects.
for example
$<idnum>= new object();
where idnum is the id from my database.
How do i dynamically assign a name to a php object?
for example how would i assign a object to a var that is the id of the db row that i am using to create objects.
for example
$<idnum>= new object();
where idnum is the id from my database.
You can use the a double dollar sign to create a variable with the name of the value of another one for example:
$idnum = "myVar";
$$idnum = new object(); // This is equivalent to $myVar = new object();
But make sure if you really need to do that, your code can get really messy if you don't have enough care or you abuse of using this "feature"...
I think you can better use arrays or hash tables rather than polluting the global namespace with dynamically created variables.