How do I add elements to an array only if they aren't in there already? I have the following:
$a=array();
// organize the array
foreach($array as $k=>$v){
foreach($v as $key=>$value){
if($key=='key'){
$a[]=$value;
}
}
}
print_r($a);
// Output
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 1
[4] => 2
[5] => 3
[6] => 4
[7] => 5
[8] => 6
)
Instead, I want $a to consist of the unique values. (I know I can use array_unique to get the desired results but I just want to know)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…