Skythrust
Member
- Jul 9, 2019
- 132
- 7
Hi guys,
I am looking for a solution to count keys in a foreach
like how many counts value A, B and C have and D, E and F.
I am able to echo the name and count via a foreach, and I have tried to use and IF statement like the example below;
Any idea how I can count the values to get this work?
I am looking for a solution to count keys in a foreach
like how many counts value A, B and C have and D, E and F.
JSON:
$json = '[{"Name":"A","Count":"3"},{"Name":"B","Count":"9"},{"Name":"C","Count":"1"},{"Name":"D","Count":"1"},{"Name":"E","Count":"4"},{"Name":"F","Count":"7"}]'
I am able to echo the name and count via a foreach, and I have tried to use and IF statement like the example below;
PHP:
<?php
$data = (json_decode($response, true));
foreach($data['tags'] as $record) {
if($record['name'] == "A" || $record['name'] == "B" || $record['name'] == "C" ||)
{count($record['count'])}
// echo $record['name']. ' - '. $record['count']. '<br>';
}
?>
Any idea how I can count the values to get this work?
Last edited: