我通过soap客户端和PHP查询一个返回以下输出的数据库;
$response = $client->executeSQLQuery(array("sql"=>$sql));
object(stdClass)#2 (1) {
["return"]=>
object(stdClass)#3 (1) {
["row"]=>
array(276) {
[0]=>
object(stdClass)#4 (4) {
["applicationuser"]=>
string(7) "rmjtapi"
["device"]=>
string(15) "SEP111111111111"
["devicedescription"]=>
string(27) "User 1"
["permissiongroup"]=>
string(20) "Standard CTI Enabled"
}
[1]=>
object(stdClass)#5 (4) {
["applicationuser"]=>
string(7) "rmjtapi"
["device"]=>
string(15) "SEP222222222222"
["devicedescription"]=>
string(13) "User 2"
["permissiongroup"]=>
string(20) "Standard CTI Enabled"
}
我想验证阵列中是否存在设备SEP111111111111。看起来我可以使用in_array函数来执行此操作,但我无法使其工作;
if (in_array("SEP111111111111", $response)))
{
echo "True";
}
有人能指出我正确的方向吗?
答案 0 :(得分:1)
尝试使用它:
$primary_array = $response->return->row;
foreach($primary_array as $a){
if($a->device == 'SEP111111111111'){
echo "true";
}
}
答案 1 :(得分:1)
Dim i As Integer
Dim test As String
For i = 0 To Main_Window.form_seg_carrier_grid.Rows - 1
If Main_Window.form_seg_carrier_grid.ValueMatrix(i, 0) = -1 Then
If test <> vbNullString Then test = test & ", "
test = test & "'"
test = test & Main_Window.form_seg_carrier_grid.ValueMatrix(i, 3)
test = test & "'"
End If
Next i
答案 2 :(得分:1)
这是您可以用来完成此任务的一般功能。请注意isset()
检查很重要,因为在尝试使用其值之前,您几乎应该总是验证响应数据的结构。
function deviceIdExistsInResponse(\stdClass $response, $deviceIdToSeek) {
if (!isset($response->return->row)) {
return false;
}
foreach ($response->return->row as $row) {
if (isset($row->device) && $row->device == $deviceIdToSeek) {
return true;
}
}
return false;
}
// Usage:
$deviceIdToSeek = 'SEP111111111111';
$deviceIdExistsInResponse = deviceIdExistsInResponse($response, deviceIdToSeek);
echo $deviceIdToSeek . ' ' . ($deviceIdExistsInResponse ? 'located' : 'not found');