我面临一个我无法解决的问题。我想要实现的是一种搜索过滤器。我有一个可以在 1 行到 +100 行之间变化的数组。数组是这样构建的:
Array
(
[0] => Array
(
[0] => PK customer
[1] => Call number
[2] => Subject of the call
[3] => Date created
[4] => Date changed
)
)
这是我的阵列之一的真实版本:
stdClass Object ( [ReadOpenCallsResult] => stdClass Object (
[ArrayOfstring] => Array
(
[0] => stdClass Object (
[string] => Array
(
[0] => 180355
[1] => C0000448207
[2] => TESTDOC
[3] => 3-7-2013 14:20:14
[4] => 3-7-2013 14:20:14
)
[1] => stdClass Object (
[string] => Array
(
[0] => 180355
[1] => C0000448209
[2] => TESTDOC
[3] => 2-7-2013 14:20:14
[4] => 2-7-2013 14:20:14
)
)
我有一个 WCF 网络服务,它在 C# 中生成一个函数结果的数组,然后将其发送到我的 PHP 页面。现在我正在测试 in_array 函数,它可以完美地与简单的数组一起使用,但我似乎无法让它与多维数组一起使用。我将数组存储到$_SESSION['searchCalls']
我用各种阵列进行了测试,但我无法让“真正的”阵列工作。我试过这样:
$key = array_search('180335',$_SESSION['searchCalls']);
而这种方式
if (in_array('180335',$_SESSION['searchCalls']))
编辑:我看到了一些非常好的示例,但是.. 当有人查找“C0000448207”然后获取调用的主题和使用它创建的日期时,是否可以获取子数组中的所有值?
这是生成对象数组的函数。
public List<List<string>> ReadOpenCalls(int relation)
{
RidderIQSDK IQSDK = new RidderIQSDK();
SDKRecordset inboundSet = IQSDK.CreateRecordset("R_ACTIONSCOPE", "PK_R_ACTIONSCOPE, DESCRIPTION, DATECREATED, DATECHANGED, CODE", "FK_RELATION = " + relation, "DATECREATED DESC ");
var messages = new List<List<string>>();
List<string> mess = new List<string>();
if (inboundSet != null && inboundSet.RecordCount > 0)
{
inboundSet.MoveFirst();
do
{
List<string> list = new List<string>();
string pkas = inboundSet.Fields["PK_R_ACTIONSCOPE"].Value.ToString();
string code = inboundSet.Fields["CODE"].Value.ToString();
string descr = inboundSet.Fields["DESCRIPTION"].Value.ToString();
string datecreated = inboundSet.Fields["DATECREATED"].Value.ToString();
string datechanged = inboundSet.Fields["DATECREATED"].Value.ToString();
list.Add(pkas);
list.Add(code);
list.Add(descr);
list.Add(datecreated);
list.Add(datechanged);
messages.Add(list);
inboundSet.MoveNext();
}
while (!inboundSet.EOF);
return messages;
}
mess.Add(null);
messages.Add(mess);
IQSDK.Logout();
return messages;
}
我自己已经解决了,这是我的解决方案,有点讨厌,但它有效。
$roc = array('relation' => $_SESSION['username']);
$rocresponse = $wcfclient->ReadOpenCalls($roc);
$_SESSION['searchCalls'] = $rocresponse;
foreach ($rocresponse->ReadOpenCallsResult as $key => $value){
if (count($value) === 0) {
}
if (count($value) === 1) {
foreach ($value as $key1 => $value1){
if (in_array($searchWord,$value1)){
echo "Value is in it";
}
}
}
else{
foreach($value as $key1 => $value1){
foreach($value1 as $key2 => $value2){
if (array_search($searchWord,$value2)){
print_r($value2);
}
}
}
}
}
我总是对更好的解决方案感兴趣,也许这个解决方案也可以帮助其他人。