I have the following snippet of code that is creating the following array...
我有以下代码片段创建以下数组...
while ($stmt->fetch()) {
foreach($row as $key => $val) {
$x[$key] = $val;
}
$results[] = $x;
}
Results in the follow array:
结果如下:
Array ( [0] => Array ( [cap_login] => master [cap_pword] => B-a411dc195b1f04e638565e5479b1880956011badb73361ca ) )
Basically I want to extract the cap_login and cap_pword values for testing. For some reason I can't get it! I've tried this kind of thing:
基本上我想提取cap_login和cap_pword值以进行测试。出于某种原因,我无法得到它!我试过这种事:
echo $results[$cap_login];
but I get the error
但我得到了错误
Undefined variable: cap_login
Can someone put me right here? Thanks.
有人能把我放在这儿吗?谢谢。
2 个解决方案
#1
3
cap_login is in an array within $results so you would have to do $results[0]['cap_login']
cap_login在$ results中的数组中,所以你必须做$ results [0] ['cap_login']
#2
1
You would have to do the following:
您必须执行以下操作:
echo $x[0]['cap_login'] . '<br />';
echo $x[0]['cap_pword'];
The reson $results[$cap_login]
wont work is because there isn't a variable called $cap_login
, there is a string called cap login. In addition, there isn't a key in $results called $cap_login. There is a value in $results called 'cap_login'
共振$ results [$ cap_login]无法工作是因为没有名为$ cap_login的变量,有一个名为cap login的字符串。另外,$ result_login中的$ result中没有关键字。 $ result中有一个名为'cap_login'的值
#1
3
cap_login is in an array within $results so you would have to do $results[0]['cap_login']
cap_login在$ results中的数组中,所以你必须做$ results [0] ['cap_login']
#2
1
You would have to do the following:
您必须执行以下操作:
echo $x[0]['cap_login'] . '<br />';
echo $x[0]['cap_pword'];
The reson $results[$cap_login]
wont work is because there isn't a variable called $cap_login
, there is a string called cap login. In addition, there isn't a key in $results called $cap_login. There is a value in $results called 'cap_login'
共振$ results [$ cap_login]无法工作是因为没有名为$ cap_login的变量,有一个名为cap login的字符串。另外,$ result_login中的$ result中没有关键字。 $ result中有一个名为'cap_login'的值