halaxa / json-machine

Efficient, easy-to-use, and fast PHP JSON stream parser
Apache License 2.0
1.08k stars 65 forks source link

Why only red is output #100

Open xcma opened 1 year ago

xcma commented 1 year ago

//fruitsArray.json { "results": [ { "name": "apple", "color": "red" }, { "name": "pear", "color": "yellow" } ] }

//code $fruits = Items::fromFile('fruitsArray.json', ['pointer' => '/results/-/color']);

foreach ($fruits as $key => $value) { var_dump($value); }

xcma commented 1 year ago
  $fruits = Items::fromString('{"results":[{"color":"red"},{"color":"yellow"}]}', ['pointer' => '/results/-/color']);
    foreach ($fruits as $key => $value) {
        var_dump($value);
    }

    output "red" and  "yellow"
xcma commented 1 year ago

$fruits = Items::fromString('{"results":[{"name":"apple","color":"red"},{"name":"pear","color":"yellow"}]}', ['pointer' => '/results/-/color']); foreach ($fruits as $key => $value) { var_dump($value); }

   only output  "red" 
halaxa commented 1 year ago

Thanks, I'll try to get to it ASAP.

halaxa commented 1 year ago

Good job with hitting the #💯btw 😂👍