3

给定

[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] 不同,但我认为这是重复的,因为有两个匹配的第一个值。其他数据无关紧要,不应进行比较。

4

1 回答 1

4

试试这个,假设这$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);
于 2012-12-17T21:50:45.563 回答