不知道如何让它看起来像

时间:2015-08-10 11:55:45

标签: php mysql

我有这些数据库列:

user_task            | user_task_id

Drive, Get something | 2, 14

所以user_task在一行中有两个任务Drive和Get something。驱动器ID 2和获取的东西是14.我如何制作看起来像的数组:

array (
   [2] => Drive,
   [14] => Get something
)

请帮助!!!

2 个答案:

答案 0 :(得分:1)

您可以使用以下内容:

$required = [];
$ids = explode(',',$row['user_task_id']);
$titles = explode(',',$row['user_task']);


foreach($ids as $index=>$id) {
   $required[$id] = $titles[$index];
}

希望这有帮助。

答案 1 :(得分:0)

您需要使用array_combineexplode功能。

实施例

print_r( array_combine(explode(', ', $row['user_task_id']), explode(', ', $row['user_task'])) );
相关问题