作者:许先生不会再想过去的事观_307 | 来源:互联网 | 2023-09-23 15:11
给定
[0] => Array
(
[0] => ask.com
[1] => 2320476
)
[1] => Array
(
[0] => amazon.com
[1] => 1834593
)
[2] => Array
(
[0] => ask.com
[1] => 1127456
)
我需要仅根据第一个值删除重复的值,而不管其他后续值是多少.注意[0] [1]与[2] [1]不同,但是我认为这是重复项,因为有两个匹配的第一个值.其他数据无关紧要,不应该在比较中考虑.
解决方法:
尝试$mainArray是您拥有的数组.
$outputArray = array(); // The results will be loaded into this array.
$keysArray = array(); // The list of keys will be added here.
foreach ($mainArray as $innerArray) { // Iterate through your array.
if (!in_array($innerArray[0], $keysArray)) { // Check to see if this is a key that's already been used before.
$keysArray[] = $innerArray[0]; // If the key hasn't been used before, add it into the list of keys.
$outputArray[] = $innerArray; // Add the inner array into the output.
}
}
print_r($outputArray);