我正在尝试在 php 中创建一个数组以发送到可用于接收用户信息的函数。
我遇到的问题是数组“复制”了它的值。这是我遇到的一个非常基本的问题,但我似乎无法克服这个问题。
这就是我的做法:
$info = array('intActive', 'intUserRole');
当我在函数中使用 var_dump 时这样做,我得到了这个:
public function employee_info($where, $info) {// Used through out to get info on employees from Assessor table
// var_dump($info);
array(1) { [0]=> string(13) "intAssessorID" } array(1) { [0]=> string(13) "intAssessorID" } // 这不应该重复
但是,当我直接在 $info 下方执行 $info 的 var_dump 时让我感到困惑的是,我得到了我需要的东西:
$info = array('intActive', 'intUserRole');
var_dump($info);
数组(2){[0]=>字符串(9)“intActive”[1]=>字符串(11)“intUserRole”}
编辑 1:
$info = array('intActive', 'intUserRole');
var_dump($info);
$emp_info = $this -> m_global -> employee_info($where, $info);
编辑 2:
我的整个脚本:
class MY_Userarea extends MY_Controller {
public function __construct() {
parent::__construct();
$login = $this -> session -> userdata('logged_in');
$id = $this -> session -> userdata('userID');
$where[":id"] = $id; // This works fine
$info = array('intActive', 'intUserRole'); // This works until it gets sent to a function called employee_info
var_dump($info);
$emp_info = $this -> m_global -> employee_info($where, $info);
if (($login !== TRUE) || ($emp_info["intActive"] !== 1) || ($emp_info["intUserRole"] === 0)) { // If no role, not activated , or not logged in then deny access
$denyaccess = TRUE;
$this -> m_global -> access_denied($denyaccess);
}
}
我的employee_info 脚本:
public function employee_info($where, $info) {// Used through out to get info on employees from Assessor table
var_dump($info);
$sql = "SELECT * FROM tableAssessor WHERE 1 ";
// Check for my where keys that I manually place.
if (array_key_exists(":active", $where)) {
$sql .= " AND intActive = :active ";
}
if (array_key_exists(":role", $where)) {
$sql .= " AND intUserRole = :role ";
}
if (array_key_exists(":id", $where)) {
$sql .= " AND intAssessorID = :id ";
}
if (array_key_exists(":email", $where)) {
$sql .= " AND txtEmail = :email ";
}
$employee_info = $this -> db -> conn_id -> prepare($sql);
$employee_info -> execute($where);
if ($employee_info) {
if ($employee_info -> rowCount() > 0) {
foreach ($employee_info -> fetchall() as $row) {
foreach ($info as $in) { // for each of the elements in the $info array use that to grab the row needed. (this works with a variable perfectly, but I want to expand it so I can retrieve more information with one function call rather then multiple calls.
$information[$in] = $row[$in];
}
}
return $information;
} else {
return FALSE;
}
}
}