title: PHP- How to assign class variable & value from string contents?
body: <p>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:</p>
  
  <pre><code>$mystring = "first_name=jane,last_name=doe";
  
  $pieces = explode(",", $mystring);
  
  foreach( $pieces as $key =&gt; $value){
      $eachvalue = explode("=",$value);
  
      class MyClass {  
  
          public $eachvalue['0'] = $eachvalue['1'];  
  
      }  
  
  } // end foreach
  
  $obj = new MyClass;
  
  echo $obj-&gt;first_name; // Should echo "Jane"
  </code></pre>
  
  <p>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...?</p>