Why wont the json_encoded data show

๐Ÿ‘:0

To output data from your json array, you should use json_decode. Assuming $data is what you declared your json array with:

<?php 
  $decoded_data = json_decode($data);
  foreach ($decoded_data->{'todoCoin'} as $todoCoin) {
    echo $todoCoin;
  }
?>

Try that in your data:[]

edit

I see where I misread that it is a multidimensional array you encoded. This is also why you are seeing array to string conversion error when trying to use echoโ€“ you have multiple arrays in an array itself. Try this in your data:[] property:

<?php 
  $decoded = json_decode($data); // decode your json 2d array
  $decoded_array = array(); // create new 1D array
  # break down the first array
  foreach ($decoded as $todoCoins) {
    # break down the second array
    foreach ($todoCoins as $todoCoin) {
      # append each value, ignoring the 'todoCoin' key, to the new 1d array
      array_push($decoded_array, $todoCoin);
    }
  }
  echo implode(", ", $decoded_array); // outputs 1,1,1,1,1,6,5,3,1, etc...
?>

Leave a comment