I have two arrays. One array is a single record array with no index - it is how all single records are provided by the vendor. The second array (having two or more records contains indexes [0] - [9]. I have a foreach loop which works great on the multiple records but the foreach does not work on the single record (which may be a string). I need a solution to test the difference between these two and the best option appears to be the index itself. Let me know if you see it differently.
Here is the array key (it is the same in every call): Array ( [0] => 0 )
Here is the single record result:
Array ( [DepositsGetInfoResult] => Array ( [DepositObject] => Array ( [Deposit_ID] => 315 [Account_ID] => 2222100000010717 [Deposit_Type] => A [Check_Date] => 2019-08-09T00:00:00 [Check_Number] => 2783 [Deposit_Amount] => 210.00 [Deposit_Status] => NSF [NSF_Reason] => INSUF FUNDS [NSF_Date] => 2019-08-09T11:33:46.397 [NSF_Code] => R01 [Creation_Date] => 2019-08-09T11:32:00 [DRC_ClientID] => 2222 [DRC_TransactionID] => 9 ) ) )
array (
'Deposit_ID' => 315,
'Account_ID' => '2222100000010717',
'Deposit_Type' => 'A',
'Check_Date' => '2019-08-09T00:00:00',
'Check_Number' => 2783,
'Deposit_Amount' => '210.00',
'Deposit_Status' => 'NSF',
'NSF_Reason' => 'INSUF FUNDS',
'NSF_Date' => '2019-08-09T11:33:46.397',
'NSF_Code' => 'R01 ',
'Creation_Date' => '2019-08-09T11:32:00',
'DRC_ClientID' => '2222',
'DRC_TransactionID' => 9,
)
Here is the multiple record result (note the indexing):
Array ( [ReceiptsGetInfoResult] => Array ( [ReceiptObject] => Array ( [0] => Array ( [Deposit_ID] => 0 [Receipt_ID] => 2777 [Account_ID] => 4555100000010792 [ClientID] => 1127 [DateReceived] => 2019-01-07T16:22:46.927 [DateEntered] => 2019-01-07T16:23:00 [Deposit_Amount] => 1.0000 [Deposit_Type] => C [DRC_ClientID] => 1196 [HoldDate] => [CCDeposit_ID] => 35 [DRC_TransactionID] => 0 ) [1] => Array ( [Deposit_ID] => 0 [Receipt_ID] => 2779 [Account_ID] => 4555100000010792 [ClientID] => 1127 [DateReceived] => 2019-01-30T10:48:35.55 [DateEntered] => 2019-01-30T10:49:00 [Deposit_Amount] => 1.0000 [Deposit_Type] => C [DRC_ClientID] => 1196 [HoldDate] => [CCDeposit_ID] => 36 [DRC_TransactionID] => 0 ) [2] => Array ( [Deposit_ID] => 0 [Receipt_ID] => 2781 [Account_ID] => 2222100000010717 [ClientID] => 1141 [DateReceived] => 2019-08-08T00:00:00 [DateEntered] => 2019-08-08T14:09:00 [Deposit_Amount] => 100.0000 [Deposit_Type] => A [DRC_ClientID] => 2222 [HoldDate] => [CCDeposit_ID] => 0 [DRC_TransactionID] => ))))
array (
0 =>
array (
'Deposit_ID' => 0,
'Receipt_ID' => 2777,
'Account_ID' => '4555100000010792',
'ClientID' => 1127,
'DateReceived' => '2019-01-07T16:22:46.927',
'DateEntered' => '2019-01-07T16:23:00',
'Deposit_Amount' => '1.0000',
'Deposit_Type' => 'C',
'DRC_ClientID' => '1196',
'HoldDate' => NULL,
'CCDeposit_ID' => 35,
'DRC_TransactionID' => 0,
),
1 =>
array (
'Deposit_ID' => 0,
'Receipt_ID' => 2779,
'Account_ID' => '4555100000010792',
'ClientID' => 1127,
'DateReceived' => '2019-01-30T10:48:35.55',
'DateEntered' => '2019-01-30T10:49:00',
'Deposit_Amount' => '1.0000',
'Deposit_Type' => 'C',
'DRC_ClientID' => '1196',
'HoldDate' => NULL,
'CCDeposit_ID' => 36,
'DRC_TransactionID' => 0,
),
2 =>
array (
'Deposit_ID' => 0,
'Receipt_ID' => 2781,
'Account_ID' => '2222100000010717',
'ClientID' => 1141,
'DateReceived' => '2019-08-08T00:00:00',
'DateEntered' => '2019-08-08T14:09:00',
'Deposit_Amount' => '100.0000',
'Deposit_Type' => 'A',
'DRC_ClientID' => '2222',
'HoldDate' => NULL,
'CCDeposit_ID' => 0,
'DRC_TransactionID' => NULL,
),
3 =>
array (
'Deposit_ID' => 313,
'Receipt_ID' => 2782,
'Account_ID' => '2222100000010717',
'ClientID' => 1141,
'DateReceived' => '2019-08-09T00:00:00',
'DateEntered' => '2019-08-09T11:32:00',
'Deposit_Amount' => '195.0000',
'Deposit_Type' => 'A',
'DRC_ClientID' => '2222',
'HoldDate' => NULL,
'CCDeposit_ID' => 0,
'DRC_TransactionID' => 8,
),
4 =>
array (
'Deposit_ID' => 315,
'Receipt_ID' => 2783,
'Account_ID' => '2222100000010717',
'ClientID' => 1141,
'DateReceived' => '2019-08-09T00:00:00',
'DateEntered' => '2019-08-09T11:32:00',
'Deposit_Amount' => '210.0000',
'Deposit_Type' => 'A',
'DRC_ClientID' => '2222',
'HoldDate' => NULL,
'CCDeposit_ID' => 0,
'DRC_TransactionID' => 9,
),
5 =>
array (
'Deposit_ID' => 0,
'Receipt_ID' => 2785,
'Account_ID' => '2222100000010717',
'ClientID' => 1141,
'DateReceived' => '2019-10-03T00:00:00',
'DateEntered' => '2019-10-03T11:51:00',
'Deposit_Amount' => '19.0000',
'Deposit_Type' => 'A',
'DRC_ClientID' => '2222',
'HoldDate' => NULL,
'CCDeposit_ID' => 0,
'DRC_TransactionID' => NULL,
),
6 =>
array (
'Deposit_ID' => 0,
'Receipt_ID' => 2787,
'Account_ID' => '2222100000010717',
'ClientID' => 1141,
'DateReceived' => '2019-09-28T00:00:00',
'DateEntered' => '2019-10-03T11:52:00',
'Deposit_Amount' => '28.0000',
'Deposit_Type' => 'A',
'DRC_ClientID' => '2222',
'HoldDate' => '2019-09-28T00:00:00',
'CCDeposit_ID' => 0,
'DRC_TransactionID' => NULL,
),
7 =>
array (
'Deposit_ID' => 0,
'Receipt_ID' => 2788,
'Account_ID' => '2222100000010717',
'ClientID' => 1141,
'DateReceived' => '2019-09-29T00:00:00',
'DateEntered' => '2019-10-03T11:52:00',
'Deposit_Amount' => '29.0000',
'Deposit_Type' => 'A',
'DRC_ClientID' => '2222',
'HoldDate' => '2019-09-29T00:00:00',
'CCDeposit_ID' => 0,
'DRC_TransactionID' => NULL,
),
8 =>
array (
'Deposit_ID' => 0,
'Receipt_ID' => 2789,
'Account_ID' => '2222100000010717',
'ClientID' => 1141,
'DateReceived' => '2019-09-30T00:00:00',
'DateEntered' => '2019-10-03T11:53:00',
'Deposit_Amount' => '30.0000',
'Deposit_Type' => 'A',
'DRC_ClientID' => '2222',
'HoldDate' => NULL,
'CCDeposit_ID' => 0,
'DRC_TransactionID' => NULL,
),
9 =>
array (
'Deposit_ID' => 417,
'Receipt_ID' => 2791,
'Account_ID' => '2222100000010717',
'ClientID' => 1141,
'DateReceived' => '2020-01-16T00:00:00',
'DateEntered' => '2020-01-16T11:15:00',
'Deposit_Amount' => '130.0000',
'Deposit_Type' => 'A',
'DRC_ClientID' => '2222',
'HoldDate' => NULL,
'CCDeposit_ID' => 0,
'DRC_TransactionID' => 7,
),
)
As I see it, I have to test for '[0]' and if zero exists then do X else do Y Count works with multiple records but does not work with the single record. I tried array_key_exists but didn't have any luck I also tried array search but I'm not getting there...
My Question is: How do I test for index 0 in this mix? I'm open to any solutions that will work in this scenario. Thanks much!
You have two different data sources here, so it's unclear why you would be running them through the same process, but you can easily tell which one is which.
The command
array_key_exists()works on the first level only, so based on the data provided, this should work without the hassle of determining if an array is indexed or associative:Now if you want to run them through the same foreach loop to pick out the common keys,