I’m starting to see the problem. Did you pay attention to the warnings?
php > $forExample = '{"sik1":"hello","sik2":"world","sik10":"today","sik41":"yesterday"}';
php > $test = json_decode($forExample);
php > $rows = count($test);
PHP Warning: count(): Parameter must be an array or an object that implements Countable in php shell code on line 1
Warning: count(): Parameter must be an array or an object that implements Countable in php shell code on line 1
That’s because decode_json returns an object by default. You need to pass the extra parameter to tell it to return an array.
json_decode($forExample, true)
Then with the other fix I mentioned, it should work.
Ah, now it’s because you’re trying to use property access syntax, when you need to use array access syntax because now it’s an array and not an object. Try this instead: