I'm facing a bit of a problem I can't fix myself. What I'm trying to achieve is sort of a search filter. I have an array which can variate between 1 row to +100 rows. The array is built like this:
Array
(
[0] => Array
(
[0] => PK customer
[1] => Call number
[2] => Subject of the call
[3] => Date created
[4] => Date changed
)
)
Here is a real version of one of my array's:
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
)
)
I have a WCF webservice which generates an array of the result of a function in C# and then sends it to my PHP page.
Now I was testing the in_array function, it works perfectly with an easy array but I can't seem to make it work with a multidimensional array.
I store my array into $_SESSION['searchCalls']
I tested with all kinds of array's but I can't get the 'real' array to work. I tried it this way:
$key = array_search('180335',$_SESSION['searchCalls']);
And this way
if (in_array('180335',$_SESSION['searchCalls']))
EDIT: I saw some really good examples, but.. is it possible to get all the values in the sub array when someone looks for 'C0000448207' and then get the subject of the call and the datecreated with it?
This is the function which generates the object arrays.
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;
}
I solved it myself already, this is my solution which is kinda nasty but it works.
$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);
}
}
}
}
}
I'm always interested in better solutions, and maybe this solution can help someone else out too.