Php 计算json中相同元素的数量
在这段简单的代码中,我用php解析jsonPhp 计算json中相同元素的数量,php,json,Php,Json,在这段简单的代码中,我用php解析json <?php $json = file_get_contents('list.json'); $data = json_decode($json,true); $records=$data['records']; foreach($records as $record) { echo $record['number']." ".$record['opened_at']; }
<?php
$json = file_get_contents('list.json');
$data = json_decode($json,true);
$records=$data['records'];
foreach($records as $record)
{
echo $record['number']." ".$record['opened_at'];
}
?>
此功能可能会有帮助:
{
"records":[
{
"number":"INC018****",
},
{
"number":"INC018****",
},
{
"number":"INC018****",
},
{
"number":"INC018****",
},
<?php
$json = file_get_contents('list.json');
$data = json_decode($json,true);
$records=$data['records'];
$numberCount = 0;
foreach($records as $record)
{
$numberCount += isset($record['number']); // Here we go
echo $record['number']." ".$record['opened_at'];
}
echo $numberCount;
?>
$counts = array_count_values($records);
$numberCount = $counts['number'];