具有相同值的数字数组

时间:2016-01-25 10:10:49

标签: php mysql

我有results的功能,它会显示来自两个不同queries的过滤numeric的名称。来自value的{​​{1}} 1-410-110的{​​{1}},其中一些结果具有相同的strings

function filter_workhires($status) {
    $status = array();
    $status[1] = 'booked';
    $status[70] = 'booked';
    $status[2] = 'partiallyattended';
    $status[90] = 'partiallyattended';
    $status[3] = 'fullyattended';
    $status[100] = 'fullyattended';
    $status[4] = 'notattended';
    $status[80] = 'notattended';
    $status[10] = 'status_user_cancelled';
    $status[20] = 'status_session_cancelled';
    $status[30] = 'status_declined';
    $status[40] = 'status_requested';
    $status[50] = 'status_approved';
    $status[60] = 'status_waitlisted';
    $status[110] = 'status_not_set';

    return $status;
}

在此表单中,我获得了double names的考试booked。如何combine statuses根据他们显示的字符串?

2 个答案:

答案 0 :(得分:2)

return array_unique($status);

关于它:)

<强>输出

Array
(
    [1] => booked
    [2] => partiallyattended
    [3] => fullyattended
    [4] => notattended
    [10] => status_user_cancelled
    [20] => status_session_cancelled
    [30] => status_declined
    [40] => status_requested
    [50] => status_approved
    [60] => status_waitlisted
    [110] => status_not_set
)

答案 1 :(得分:0)

更改它,因此描述是数组键,状态的ID是值。当你构建数组并且你复制了一个副本时,你可以在某种结构中添加多个ID,就像逗号分隔的字符串一样。所以你最终得到:

     $status['booked'] = '70';
     $status['partiallyattended'] = '2, 90';
     $status['fullyattended'] = '3, 10';
...

当有人选择某个项目时,您会触发该值并获取与该状态相关的所有ID。