문제

Maybe I'm missing something here, but array_diff() seems to be leaving me empty kesys at the end of an array.

With this example data -

$term_ids = array(0 => 242, 1 => 270);
$term_ids = array_diff($term_ids, array(242, 243, 266, 267, 268, 269));

I am being left with this -

Array
(
    [1] => 270
    [0] => 
)

From what I understand, this is incorrect ([0] should be unset, leaving just [1]). I am using $term_ids = array_values($term_ids); after to make the keys correct, but it seems that this should not be necessary, so I'm wondering if someone who knows more than me could clarify?

도움이 되었습니까?

해결책

I tried

<?php

$arr1 = array(15, 16, 17,18);
$arr2 = array(15, 17);

$arr3 = array_diff($arr1, $arr2);

var_dump($arr3);

?>

and I got [1] => 16, [3] => 18.

This actually seems to be the intended result as the example on the offical page shows.

다른 팁

Unable to reproduce:

$term_ids = array(0 => 242, 1 => 270);
$term_ids = array_diff($term_ids, array(242, 243, 266, 267, 268, 269));
print_r($term_ids);

Output:

Array
(
    [1] => 270
)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top