传递数组并检查值

时间:2017-11-16 10:38:14

标签: php mysql

在创建具有用户ID的组时,我正在检查输入的ID是否存在于数据库中。如果存在,则应创建组,否则应该弹出错误。

我将带有用户ID的数组传递给函数user_check,但是没有检查它。这是我的代码:

<?php

    function user_check($user_id)
    {
        $u1 = mysqli_query($con, "SELECT uid from users where uid<>'" . $_SESSION['user_id'] . "'");
        while ($row = mysqli_fetch_array($u1)) {
            $users = $row['uid'];
            echo "users" . $users;
            $users1 = sort($users);
            $users2 = sort($user_id);
            printf($users1);
            if ($user1 == $user2) {
                echo "same";
            } else {
                echo "not same";
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

给定一个user_id列表(您已经验证/已经过滤),您可以编写类似以下内容的函数(未经测试):

class ChangeQualificationToArray < ActiveRecord::Migration

  def change
    change_column :coaches, :qualifications, "varchar[] USING (string_to_array(qualifications, ';'))"
  end

end