$arrempty =array();
for($i=0;$i<count($courseinfo['olinelist']);$i++){
if(!in_array($courseinfo['olinelist'][$i]['onday'],$arrempty)){
echo "<pre>";
print_r($courseinfo['olinelist']);
}
}
INPUT:
Array
(
[date] => 2016-02-23
[onday] => 1
[session] => Morning
[start_time] => 08:30:00
[cd_desc] => REGISTRATION
[end_time] => 09:00:00
[Name] => Fname Lname
[profile_Pic] => 145464959476.jpg
)
Array
(
[date] => 2016-02-23
[onday] => 1
[session] => Morning
[start_time] => 09:30:00
[cd_desc] => ON LABEL VS OFF LABEL (BOTOX)
[end_time] => 09:45:00
[Name] => Fname Lname
[profile_Pic] => 145464959476.jpg
)
Array
(
[date] => 2016-02-23
[onday] => 2
[session] => Morning
[start_time] => 09:00:00
[cd_desc] => INTRODUCTION
[end_time] => 09:15:00
[Name] => Fname Lname
[profile_Pic] => 145464959476.jpg
)
Array
(
[date] => 2016-02-20
[onday] => 2
[session] => Morning
[start_time] => 01:00:00
[cd_desc] => Lunch
[end_time] => 02:15:00
[Name] => Fname Lname
[profile_Pic] => 146.jpg
)
Output:
date =>
onday => 1
session =>
start_time => 08:30:00
cd_desc => REGISTRATION
end_time => 09:00:00
Name => Fname Lname
profile_Pic => 145464959476.jpg
date =>
onday =>
session =>
start_time => 09:30:00
cd_desc => ON LABEL VS OFF LABEL (BOTOX)
end_time => 09:45:00
Name => Fname Lname
profile_Pic => 145464959476.jpg
date =>
onday => 2
session =>
start_time => 09:00:00
cd_desc => INTRODUCTION
end_time => 09:15:00
Name => Fname Lname
profile_Pic => 145464959476.jpg
date =>
onday =>
session =>
start_time => 01:00:00
cd_desc => Lunch
end_time => 02:15:00
Name => Fname Lname
profile_Pic => 146.jpg
查看日期,在显示每个循环时,会话应为空白
我想要做的是从数组中删除重复的元素值并将密钥保持为空白。我曾尝试使用array_unique($ myarray),但它似乎无法正常工作。请帮忙!!!
答案 0 :(得分:0)
试试这个:
$arrempty =array();
for($i=0;$i<count($courseinfo['olinelist']);$i++){
if(!in_array($courseinfo['olinelist'][$i]['onday'],$arrempty['onday'])){
$arrempty[] = $courseinfo['olinelist'][$i];
echo "<pre>";
print_r($courseinfo['olinelist'][$i]);
}
}