score:1

Accepted answer

please try this:

$lowvalue = [];
foreach ($data->data[$i] as $obj) {
    if (isset($obj->close)) {
        // add the element to the beginning of the array
        array_unshift($lowvalue, $obj->close);
    }

    if(count($lowvalue) >= 30) {
        break;
    }
}

echo json_encode(['data' => $lowvalue]);

regarding your second question you should create another question on so.

score:0

with @mapek 's help and after i've worked a bit on his example the solution in my case was:

data:<?php
       $lowvalue = [];
       foreach ($data->data as $obj) {
          if (isset($obj->close)) {
              // add the element to the beginning of the array
              array_unshift($lowvalue, $obj->close);
          }

          if(count($lowvalue) >= 30) {
                   break;
          }
       }
       $low = array_map( create_function('$value', 'return (int)$value;'),
                                    $lowvalue);
       echo json_encode($low);
                ?>

which displays my array like this: data:[621, 512, 578]...


Related Query

More Query from same tag