清除数组中的重复值吗?
大家好,
有人可以请帮帮我吗,我已经尝试解决这个问题有一段时间了,现在摸不着头脑。
我正在添加指向 SESSION 数组的链接,这是我的代码。
session_start();
$test = $_GET;
$_SESSION['value'][]=$test;
echo "<pre>";
//print_r($_SESSION);
echo "</pre>";
$turn = $_SESSION['value'];
foreach (array_reverse($turn) as $value) {
$furl = "http://example.s3.amazonaws.com/".urlencode($value['tune_name']);
echo $furl;
}
这是我的 print_r($_SESSION); 的结果
Array
(
[attach] => Array
(
)
[backups-2] => true
[dnb] => true
[house] => true
[tech-house] => true
[uk-garage] => true
[uk-grime] => true
[uk-hip-hop] => true
[uncategorized] => true
[warehouse] => true
[active] =>
[value] => Array
(
[0] => Array
(
[tune_name] => Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[submit] => Listen
)
[1] => Array
(
)
[2] => Array
(
[tune_name] => Music/dnb/Abort_Delta Heavy_192.mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/Abort_Delta Heavy_192.mp3
[submit] => Listen
)
[3] => Array
(
[tune_name] => Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[submit] => Listen
)
[4] => Array
(
[tune_name] => Music/dnb/21st Century (Feat. Cabbie)_Tantrum Desire_192.mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/21st Century (Feat. Cabbie)_Tantrum Desire_192.mp3
[submit] => Listen
)
[5] => Array
(
[tune_name] => Music/dnb/Abort_Delta Heavy_192.mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/Abort_Delta Heavy_192.mp3
[submit] => Listen
)
[6] => Array
(
)
[7] => Array
(
[tune_name] => Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[submit] => Listen
)
[8] => Array
(
[tune_name] => Music/dnb/Abort_Delta Heavy_192.mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/Abort_Delta Heavy_192.mp3
[submit] => Listen
)
)
)
所以我想做的是循环遍历该数组并显示链接,但我不知道任何重复的值。
$turn = $_SESSION['value'];
foreach (array_reverse($turn) as $value) {
$furl = "http://example.s3.amazonaws.com/".urlencode($value['tune_name']);
echo $furl;
}
这是我从 foreach 得到的结果。
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F03+Twerk+feat.+Yo+Majesty+%28Sub+Focus+Remix%29.mp3
http://example.s3.amazonaws.com/
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F21st+Century+%28Feat.+Cabbie%29_Tantrum+Desire_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F03+Twerk+feat.+Yo+Majesty+%28Sub+Focus+Remix%29.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/
太烦人了,我只想让它显示出来。
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F03+Twerk+feat.+Yo+Majesty+%28Sub+Focus+Remix%29.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F21st+Century+%28Feat.+Cabbie%29_Tantrum+Desire_192.mp3
因为上面没有任何重复的值,所以我尝试了很多 array_unique 对我不起作用,有人可以帮忙吗?
HI all
Can someone please please help me been trying to suss this for a while now scratching my head.
I am adding links to a SESSION array here is my code.
session_start();
$test = $_GET;
$_SESSION['value'][]=$test;
echo "<pre>";
//print_r($_SESSION);
echo "</pre>";
$turn = $_SESSION['value'];
foreach (array_reverse($turn) as $value) {
$furl = "http://example.s3.amazonaws.com/".urlencode($value['tune_name']);
echo $furl;
}
here is the result off my print_r($_SESSION);
Array
(
[attach] => Array
(
)
[backups-2] => true
[dnb] => true
[house] => true
[tech-house] => true
[uk-garage] => true
[uk-grime] => true
[uk-hip-hop] => true
[uncategorized] => true
[warehouse] => true
[active] =>
[value] => Array
(
[0] => Array
(
[tune_name] => Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[submit] => Listen
)
[1] => Array
(
)
[2] => Array
(
[tune_name] => Music/dnb/Abort_Delta Heavy_192.mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/Abort_Delta Heavy_192.mp3
[submit] => Listen
)
[3] => Array
(
[tune_name] => Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[submit] => Listen
)
[4] => Array
(
[tune_name] => Music/dnb/21st Century (Feat. Cabbie)_Tantrum Desire_192.mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/21st Century (Feat. Cabbie)_Tantrum Desire_192.mp3
[submit] => Listen
)
[5] => Array
(
[tune_name] => Music/dnb/Abort_Delta Heavy_192.mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/Abort_Delta Heavy_192.mp3
[submit] => Listen
)
[6] => Array
(
)
[7] => Array
(
[tune_name] => Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[submit] => Listen
)
[8] => Array
(
[tune_name] => Music/dnb/Abort_Delta Heavy_192.mp3
[tune] => http://example.s3.amazonaws.com/Music/dnb/Abort_Delta Heavy_192.mp3
[submit] => Listen
)
)
)
so what i am trying to do is loop through that array and show the link but i dont what any duplicate values.
$turn = $_SESSION['value'];
foreach (array_reverse($turn) as $value) {
$furl = "http://example.s3.amazonaws.com/".urlencode($value['tune_name']);
echo $furl;
}
and this is the result i get from the foreach.
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F03+Twerk+feat.+Yo+Majesty+%28Sub+Focus+Remix%29.mp3
http://example.s3.amazonaws.com/
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F21st+Century+%28Feat.+Cabbie%29_Tantrum+Desire_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F03+Twerk+feat.+Yo+Majesty+%28Sub+Focus+Remix%29.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/
So annoying i only want it to show.
http://example.s3.amazonaws.com/Music%2Fdnb%2FAbort_Delta+Heavy_192.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F03+Twerk+feat.+Yo+Majesty+%28Sub+Focus+Remix%29.mp3
http://example.s3.amazonaws.com/Music%2Fdnb%2F21st+Century+%28Feat.+Cabbie%29_Tantrum+Desire_192.mp3
Because above doesnt have any duplicate values i have tried so much array_unique hasnt worked for me can someone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用关联数组来检查它是否已经输出。
使用
$furl
作为键。You can use an associative array to check if it's already outputted.
Use
$furl
as a key.没问题。试试这个:
它将从数组 $arr 中删除所有重复的值。
No problem. Try this:
It will remove any duplicate values from the array $arr.
尝试更改
为
这样
try changing
to
so it looks like this
也许你可以使用
array_unique
它会过滤掉所有重复的值,例如:结果应该是:
maybe you can use
array_unique
it filters out all duplicated values like:result should be: