[英]PHP Array always returning null
I'm just using a single-dimension array, nothing special 我只是在使用一维数组,没什么特别的
$invalid_custom_transaction_ids = array();
Method 1: 方法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: 方法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() 以下内容打印到调试日志中,显示我尝试将某些值添加到array()
[03-Nov-2014 08:48:25 America/Los_Angeles] [PUSHING]Ux837Yn3rK3 [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 当我尝试使用以下代码将数组打印到debug_log时
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: 输出到error_log文件看起来像这样:
[03-Nov-2014 08:48:25 America/Los_Angeles] [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 [03-Nov-2014 08:48:25 America / Los_Angeles] PHP警告:在第195行的/path/to/script.php中为foreach()提供了无效的参数
The code that is on line 195 is as follow: 195行上的代码如下:
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- -snip-
Your mistake is that var_dump
does not return a string. 您的错误是var_dump
不返回字符串。 It prints to standard output. 打印到标准输出。 When you write error_log(var_dump(...))
it is not writing the var_dump output to your error log. 当您编写error_log(var_dump(...))
它并未将var_dump输出写入错误日志。
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)
? 您可以打印出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
. 好的,所以您的问题是,在uniqueTransactionCheck()
您引用了一个名为$invalid_custom_transaction_ids
的变量。
However, that variable does not exist in the scope of uniqueTransactionCheck()
. 但是,该变量在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: 如果您在uniqueTransactionCheck()
运行以下代码,您将在日志中看到错误打印:
error_log(isset($invalid_custom_transaction_ids))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.