$dom = $html->find('.someClass',0)->find('.studentID');
$arr = array();
foreach ($dom as $data) {
if(isset($data->find('.studentID',0)->plaintext)){
$studentID = $data->find('.studentID',0)->plaintext;
$arr[] = array(
'studentID'=>$studentID
);
}
}
如果我回显$studentID
,结果将是123,345,345,567,123,567
我的数据包含冗余值。
我想要的只有123,345和567。
在将$ studentID分配到$ arr之前,我该怎么做?我不能使用in_array(),因为我循环遍历字符串,在这种情况下不是数组。
答案 0 :(得分:0)
获取该信息并将其放入数组中,然后执行任何其他类型比较的in_array。像array_unique。
$studentIdArr = explode(", ", $studentId);
答案 1 :(得分:0)
采取@ dan08回答
<?php
$result = array_unique($arr);
print_r($result);
?>
将返回一组唯一的非冗余值并输入
答案 2 :(得分:0)
您可能(无法确定足够的代码)将学生ID用作$ arr数组中的键。分配数据时,只需执行以下操作:
$arr[$studentID] = array(
'studentID'=>$studentID
);
通过这种方式,您知道学生ID只会在列表中出现一次。只需确保仔细检查数据结构,以确保它对您的用例有效。