title: Retrieve object variables with dynamic key strings
body: <p>I have a PHP object with an attribute named "required". This "required" field is a nested array. I want to retrieve a desired key from this object with dynamic strings (for attribute names and array indexes). How can I achieve that?</p>
  
  <pre><code>$myObj = new StdClass;
  $myObj-&gt;required = array(
          "name_required" =&gt; 1,
          "courses" =&gt; array(
                  "course_name_required" =&gt; 1,
                  "lessons_required" =&gt; 1,
                  "lessons" =&gt; array(
                          "lesson_name_required" =&gt; 1,
                          "lesson_file_required" =&gt; 1,
                          "is_viewed_required" =&gt; 1,
                      ),
              ),
  
  );
  // Desired Key I want to retrieve using dynamic strings.
  $desiredKeyArrayPart = "[courses][lessons][lesson_name_required]";
  $desiredKeyAttributePart = "required";
  $desiredKey = $desiredKeyAttributePart . $desiredKeyArrayPart;
  
  // Get the value (Should return 1)
  $desiredValue = $myObj-&gt;$desiredKey;
  </code></pre>
  
  <p>I want the value 1 to be returned but this throws a runtime error:
      PHP Notice:  Undefined property: stdClass::$required[courses][lessons][lesson_name_required]</p>