title: PHP - How to get key values from a dynamic JSON response
body: <p>I have a JSON response and my code needs to pull out key values if a certain value exist.</p>
  <p>For example.</p>
  <blockquote>
  <p>If this title exist, then display it's key value etc.</p>
  </blockquote>
  <p>Here's my JSON package:</p>
  <pre><code>{
      &quot;Data&quot;: {
          &quot;Rows&quot;: [{
              &quot;Title&quot;: &quot;Economy Road&quot;,
              &quot;ServiceType&quot;: &quot;6. Economy Road (Pallets)&quot;,
              &quot;GrandPrice&quot;: 14.50
          }, {
              &quot;Title&quot;: &quot;Road Freight&quot;,
              &quot;ServiceType&quot;: &quot;1. Road Freight&quot;,
              &quot;GrandPrice&quot;: 16.50
          }, {
              &quot;Title&quot;: &quot;Home Delivery&quot;,
              &quot;ServiceType&quot;: &quot;Platinum&quot;,
              &quot;GrandPrice&quot;: 10.50
          }]
      }
  }
  </code></pre>
  <p>How would I loop through this JSON data and display the GrandPrice if it matches the ServiceType?</p>
  <p>For example, if ServiceType = &quot;1. Road Freight&quot; then display GrandPrice of 16.50 etc.</p>
  <p>I also tried to decode the json data and pull out the key value using a fixed index number like so:</p>
  <blockquote>
  <p>$data_result_json_decoded-&gt;Data-&gt;Rows[1]-&gt;ServiceType;</p>
  </blockquote>
  <p>However this JSON response is not fixed and is dynamic.</p>
  <p>Any help would greatly be appreciated.</p>