I have a string that I'm trying to use to create a class. I am trying to name each property and define its value based on the contents of the string. For example:
$mystring = "first_name=jane,last_name=doe";
$pieces = explode(",", $mystring);
foreach( $pieces as $key => $value){
$eachvalue = explode("=",$value);
class MyClass {
public $eachvalue['0'] = $eachvalue['1'];
}
} // end foreach
$obj = new MyClass;
echo $obj->first_name; // Should echo "Jane"
I'm pretty new PHP classes, and this isn't working. I don't know if I'm close, or if I'm way off...?