title: Retrieving dynamically generated JSON keys and values
body: <p>I have the JSON structure below that I'm pulling into my PHP script as a $_POST request. The keys for the Campaign Names and Group Names are dynamically generated so I need to extract those keys so I can then group each campaign with it's group name and ad copy into separate arrays.</p>
  
  <p>I've seen several posts here that are very similar but none of those solutions have worked so far. I feel I'm over-complicating this.</p>
  
  <pre><code>{
      "First Campaign Name": {
          "First Group Name": {
              "textads": [
                  [
                      "{Headline text}",
                      "First line text",
                      "Second line text",
                      "Display URL"
                  ],
                  [
                      "{Headline text}",
                      "First line text",
                      "Second line text",
                      "Display URL"
                  ]
              ]
          },
          "Second Group Name": {
              "textads": [
                  [
                      "{Headline text}",
                      "First line text",
                      "Second line text",
                      "Display URL"
                  ],
                  [
                      "{Headline text}",
                      "First line text",
                      "Second line text",
                      "Display URL"
                  ]
              ]
          }
      },
      "Second Campaign Name": {
          "First Group Name": {
              "textads": [
                  [
                      "{Headline text}",
                      "First line text",
                      "Second line text",
                      "Display URL"
                  ],
                  [
                      "{Headline text}",
                      "First line text",
                      "Second line text",
                      "Display URL"
                  ]
              ]
          },
          "Second Group Name": {
              "textads": [
                  [
                      "{Headline text}",
                      "First line text",
                      "Second line text",
                      "Display URL"
                  ],
                  [
                      "{Headline text}",
                      "First line text",
                      "Second line text",
                      "Display URL"
                  ]
              ]
          }
      }
  }
  </code></pre>
  
  <p>I've tried several foreach and nested foreach loops in trying to access the keys and values with no luck. My most recent attempts are:</p>
  
  <pre><code>foreach($jsonString as $campaign) {
      foreach($campaign as $k =&gt; $v){
          $postData .= "Key: " . $k . "\r\n";
          $postData .= "Val: " . $v . "\r\n";
      }
  }
  </code></pre>
  
  <p>Where $postData is already defined and then saved to a file for output.
  I also attempted the following:</p>
  
  <pre><code>foreach ($_POST as $key =&gt; $value) {
      foreach( $value as $item){
          foreach( $item as $k =&gt; $v){
             $postData .= "Key: " . $k . "\r\n";
             $postData .= "Val: " . $v . "\r\n";
          }
      }
  }
  </code></pre>