title: How can I increment value of json data if it meets certain conditions?
body: <p>My json data is like this :</p>
  <pre><code>$json_data = '{&quot;1&quot;: &quot;1&quot;, &quot;2&quot;: &quot;1&quot;}';
  </code></pre>
  <p>Note :</p>
  <blockquote>
  <p>1 = star</p>
  <p>1 = the number of users who give star 1</p>
  <p>2 = star</p>
  <p>1 = the number of users who give star 2</p>
  </blockquote>
  <p>If I have variables like this :</p>
  <pre><code>$star = 1;
  </code></pre>
  <p>I want check variable <code>$star </code> exist in key of <code>$json_data</code> or not</p>
  <p>If exist, it will update to be :</p>
  <pre><code>$json_data = '{&quot;1&quot;: &quot;2&quot;, &quot;2&quot;: &quot;1&quot;}';
  </code></pre>
  <p>So, if <code>$star</code> exist in key of <code>$json_data</code>, it will increment the value</p>
  <p>I try like this :</p>
  <pre><code>&lt;?php 
      $star = 1;
      $json_data = '{&quot;1&quot;: &quot;1&quot;, &quot;2&quot;: &quot;1&quot;}';
      $array_data = json_decode($json_data, true);
      if(array_key_exists($star, $array_data)) {
          $value = $array_data[$star];
          if ($value !== false) {
              // update here
          }
                     
      }
  ?&gt;
  </code></pre>
  <p>I'm still confused, how to update it</p>
  <p>Is there anyone who can help me?</p>