我已经习惯从字符串中获取一些数据,现在我需要从中删除重复数据。
我的代码是:
for ($i = 0, $l = count($videos); $i < $l; $i++) {
$video = explode('>>',$videos[$i]);
$audio = str_replace(' ','',$video[2]);
$subs = str_replace(' ','',$video[3]);
$lang = $audio.'_'.$subs.', ';
}
返回此内容:
es_en, en_es, es_en, es_en, en_es, en_en,
有没有办法用PHP删除它的副本?
答案 0 :(得分:1)
$cache = [];
for ($i = 0, $l = count($videos); $i < $l; $i++) {
$video = explode('>>',$videos[$i]);
$audio = str_replace(' ','',$video[2]);
$subs = str_replace(' ','',$video[3]);
$lang = $audio.'_'.$subs;
if (!in_array($lang, $cache)){
$cache[] = $lang;
}
}
$result = implode(',', $cache);