title: Convert php multidimensional array to json format to use in Jquery $.post
body: <p>With <code>fetchAll(PDO::FETCH_ASSOC)</code> get such array</p>
  
  <pre><code>$array = 
  Array
  (
      [0] =&gt; Array
          (
              [FinalCurrencyRate] =&gt; 0.000062
          )
  )
  </code></pre>
  
  <p>Need to <code>json_encode</code> to use in </p>
  
  <pre><code>$.post("__02.php", { 'currency': currency }, function(data, success) {
  $('#currency_load').html(data.FinalCurrencyRate);
  $('#currency_load0').html(data.FinalCurrencyRate0);
  $('#currency_load1').html(data.FinalCurrencyRate1);//and so on
  }, "json");
  </code></pre>
  
  <p>If simply <code>echo json_encode($array);</code> then does not work.</p>
  
  <p>Need to convert to json format array like this:</p>
  
  <p><code>$arr = array ('FinalCurrencyRate'=&gt;"0.000062");</code></p>
  
  <p>To convert to json format, wrote such code</p>
  
  <pre><code>$json_array = "{";
  $flag_comma = 0;
  foreach($array as $i =&gt;$array_modified) {
  
  if ($flag_comma == 0) {
  $json_array .="'FinalCurrencyRate". $i."'=&gt;'". $array_modified[FinalCurrencyRate]. "'";
  $flag_comma = 1;
  }
  else {
  $json_array .=", 'FinalCurrencyRate". $i."'=&gt;'". $array_modified[FinalCurrencyRate]. "'";
  }
  
  }
  $json_array .= "}";
  </code></pre>
  
  <p>Then <code>echo json_encode($json_array);</code>. And only one <code>echo json_encode</code>.</p>
  
  <p>But does not work.</p>
  
  <p>Understand that there are errors in code to convert to json format. What need to correct, please?</p>