我需要比较一些数组中的值。 这个数组是多维的,我需要比较内部的数组。
在这里转储:
php
array (size=4)
1 =>
array (size=3)
0 => string '96' (length=2)
1 => string '90' (length=2)
2 => string '91' (length=2)
2 =>
array (size=3)
0 => string '96' (length=2)
1 => string '90' (length=2)
2 => string '91' (length=2)
3 =>
array (size=4)
0 => string '96' (length=2)
1 => string '90' (length=2)
2 => string '91' (length=2)
3 => string '98' (length=2)
4 =>
array (size=4)
0 => string '96' (length=2)
1 => string '90' (length=2)
2 => string '91' (length=2)
3 => string '98' (length=2)
我想使用类似array_diff
的东西来比较不同的数组,但是...即使看起来很愚蠢,我也不知道该怎么做。
我想我希望“提取”这4个数组,以便能够进行比较。
有人可以向我解释这样做的好方法吗? 非常感谢。
答案 0 :(得分:0)
var chart = new Chart(ctx, {
// The type of chart we want to create
type: 'line', // also try bar or other graph types
// The data for our dataset
data: {
labels: $.getMonths(year+'-01-01',year+'-12-31'),
// Information about the dataset
datasets: [
{
label: "Converted",
borderColor: 'Green',
data: leadsConvertedAtCountPerMonthPerYear,
},
{
label: "Contacted",
borderColor: 'red',
data: leadsContactedAtCountPerMonthPerYear,
},
{
label: "Assigned",
borderColor: 'royalblue',
data: leadsAssignedAtCountPerMonthPerYear,
},
]
},
// Configuration options
options: {
layout: {
padding: 10,
},
legend: {
position: 'bottom',
},
title: {
display: true,
text: 'Reports for '
},
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Precipitation in mm'
}
}],
xAxes: [{
scaleLabel: {
display: true,
labelString: 'Month of the Year'
}
}]
}
}
<?php
$arr = [
['96','90','91'],
['96','90','91'],
['96','90','91','98'],
['96','90','91','98'],
];
$set = [];
foreach ($arr as $values) {
foreach($values as $each_value){
if(!isset($set[$each_value])) $set[$each_value] = true;
}
}
$result = [];
$set = array_keys($set);
foreach ($arr as $values) {
foreach($set as $value){
if(!in_array($value,$values)) $result[] = $value;
}
}
$result = array_unique($result);
print_r($result);
中。