Reputation: 16192
I'm just using a single-dimension array, nothing special
$invalid_custom_transaction_ids = array();
Method 1:
foreach($result as $row) {
if($row['TransactionID'] == $paypal_transaction_id) {
error_log("[DIE]1");
die();
}
error_log("[PUSHING]".$row['CustomTransID']);
array_push($invalid_custom_transaction_ids, $row['CustomTransID']);
}
Method 2:
foreach($result as $row) {
if($row['TransactionID'] == $paypal_transaction_id) {
error_log("[DIE]1");
die();
}
error_log("[PUSHING]".$row['CustomTransID']);
$invalid_custom_transaction_ids[] = $row['CustomTransID'];
}
The following is printed to the debug log, showing that there are values that I've tried adding to the array()
[03-Nov-2014 08:48:25 America/Los_Angeles] [PUSHING]Ux837Yn3rK3
When I try to print the array to the debug_log using the following code
error_log(var_dump($invalid_custom_transaction_ids));
it returns blank, I've also tried this
error_log(array_values($invalid_custom_transaction_ids));
Output to the error_log file looks like this:
[03-Nov-2014 08:48:25 America/Los_Angeles]
Then the following error is printed
[03-Nov-2014 08:48:25 America/Los_Angeles] PHP Warning: Invalid argument supplied for foreach() in /path/to/script.php on line 195
The code that is on line 195 is as follow:
function uniqueTransactionCheck() {
error_log("[UTC]1");
error_log(var_dump($invalid_custom_transaction_ids));
error_log("Is array: " . is_array($invalid_custom_transaction_ids));
foreach($invalid_custom_transaction_ids as $invalid) {
if($custom_transaction_id == $invalid) {
$custom_transaction_id = generateTransactionID();
uniqueTransactionCheck();
}
}
}
What's the deal? I don't understand this at all, I've been trying and trying to get this right, and shuffling through different documentaries and methods. I'm absolutely flabbergasted.
-snip-
Upvotes: 0
Views: 69
Reputation: 8991
Your mistake is that var_dump
does not return a string. It prints to standard output. When you write error_log(var_dump(...))
it is not writing the var_dump output to your error log.
It looks to me that the type of the variable is not an array as you expect. Can you print out the result of is_array($invalid_custom_transaction_ids)
?
EDIT:
Ok so your issue is that in uniqueTransactionCheck()
you are referencing a variable called $invalid_custom_transaction_ids
.
However, that variable does not exist in the scope of uniqueTransactionCheck()
. You probably want to pass the variable as an argument. If you run the following code in uniqueTransactionCheck()
you will see false printed in your logs:
error_log(isset($invalid_custom_transaction_ids))
Upvotes: 2