我想創建一個數組在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);
陣列(1){[0] = > string(13)「intAssessorID」} array(1){[0] => string(13)「intAssessorID」} //這不應該被複制
然而,是什麼讓我困惑的時候我直接做$信息一的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;
}
}
}
你能告訴我們'$ info = array(...)'和調用'employee_info(...)'函數之間會發生什麼嗎? – Stobor
已更新原始文章 – user2378411
嗯...是'intAssessorID'的元素$ where或$ info? – Stobor