我遇到这个问题有些困难。当我尝试运行此代码时,会显示Notice: Undefined variable: errors in C:\xampp\htdocs\Bots\botanize.php on line 5
和Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\Bots\botanize.php on line 5
,但我不确定如何操作。我尝试了不同的方法,但他们不会工作。有什么想法吗?
<?php
$errors = array();
$error_num = 1;
function checkErrors(){
foreach($errors as $e){
if(count($errors)>0){
echo "Error " . $error_num . ": " . $e . "<br />";
}
die();
}
}
function curl_connection($website, $method, $data){
if(strlen($website) < 1){
array_push($errors, "The first parameter is not filled out!");
}
if(strlen($method) < 1){
array_push($errors, "The second parameter is not filled out!");
}
if(strlen($data) < 1){
array_push($errors, "The third parameter is not filled out!");
}
if(is_array($data)){
array_push($errors, "The third parameter needs an array. Not a variable.");
}
if($method != 'POST' || $method != 'GET'){
array_push($errors, "The second parameter needs a method type of POST or GET. Make sure the POST or GET is all capitalized.");
}
}
checkErrors();
?>