我有一个像这样的数组:
$array = [['name'=> 'one'], ['name'=>'two'],['name'=> 'three'], ['name'=>'four']];
我想比较/打印该阵列中的每个组合:
一个 - >二 一个 - >三 ... 二 - >三 二 - > 4
依旧......
我试过
<?php foreach ($compares as $k1 => $v1 ){
echo $v1->id.'<br>';
foreach ($compares2 as $k2 => $v2 ){
if($k1 == $k2) echo $v2->id.'<br>';
}
}
?>
答案 0 :(得分:0)
我不知道我是否正确理解您的要求(如果您愿意,我可以修改它)。看看这个例子:
<?php
$array = [
['name'=> 'one'],
['name'=>'two'],
['name'=> 'three'],
['name'=>'four']
];
for ($i = 0; $i < count($array)-1; $i++) {
for ($j = $i+1; $j < count($array); $j++) {
echo $array[$i]['name'] . ' > ';
echo $array[$j]['name'] . '<br>';
}
}
答案 1 :(得分:0)
Pavels答案似乎是正确的,也许你应该检查你的重复值?
@Override
@TriggersRemove(removeAll = true, cacheName = TRUNCATE_PARAMS_CACHE_NAME,
keyGenerator = @KeyGenerator(name = CACHE_KEY_GENERATOR,
properties = @Property(name = "includeMethod", value = "false")))
public void evictAll() {
LOGGER.info("Evicting all truncation candidates");
}
}
输出:
<?php
$array = [['id'=> 'one'],['id'=>'two'],['id'=> 'three'],['id'=>'four']];
for ($i = 0; $i < count($array)-1; $i++) {
for ($j = $i+1; $j < count($array); $j++) {
echo $array[$i]['id'] . ' - ';
echo $array[$j]['id'] . '<br>';
}
}
?>