我对函数的实现一定有一些误解,$get_ship_class -> check_array($category,$cat_in_class = array());因为它抛出了错误:致命错误:未捕获的 ArgumentCountError:函数 get_ship_class::check_array() 的参数太少,第 60 行在 C:\xampp\htdocs\php_sandbox\assign_ship_class.php 中传递了 0,在 C:\xampp\htdocs\php_sandbox 中预期至少有 1 个\assign_ship_class.php:45 堆栈跟踪:#0 C:\xampp\htdocs\php_sandbox\assign_ship_class.php(60): get_ship_class->check_array() #1 {main} 在 C:\xampp\htdocs\php_sandbox\assign_ship_class 中抛出第 45 行的 .php作为回应,我尝试过$get_ship_class->check_array($category, $cat_in_class = array()),但没有奏效。本质上,第一个函数get_class_categories()以数组的形式检索特定运输类别下的产品类别。function get_product_category($category)检索手头当前产品的类别 - 我们将假装;在这种情况下设置 $category = "Monitors"。最后check_array();只检查 $category = Monitors 是否与此运输类别的类别列表中的任何元素匹配,该类别由get_class_categories()函数生成。 <?phpclass get_ship_class{ public function get_class_categories() { $csv = array_map("str_getcsv", file("Shipping Classes.csv")); /*print_r($csv);echo "<br />";*/ $header = array_shift($csv); // Separate the header from data /* print_r($header);echo "<br />";*/ $col = array_search("Com1_34-95", $header); /*print_r($col);*/ foreach ($csv as $row) { $array[] = $row[$col]; } $cat_in_class = array_filter($array); print_r($cat_in_class); //https://stackoverflow.com/a/30909191/9095603 $this->check_array($cat_in_class); // pass array onto function below } public function get_product_category() { $this->category = 'Monitor'; //echo $this->category; } public function check_array($category, $cat_in_class = array()) {// https://stackoverflow.com/a/6431836/9095603//$this->category='Monitor'; $this->category; if (in_array($this->category, $cat_in_class)) { echo "Match detected!"; } }
1 回答
阿波罗的战车
TA贡献1862条经验 获得超6个赞
我同意@u_mulder。无论如何,我想给你一个答案。
您的代码调用该check_array
函数两次:
在
get_class_categories
函数结束时,只传递一个参数:$cat_in_class
- 不是两个在 php 文件的末尾,移交空参数。
我建议您执行代码审查。一旦确定了控制流,您就应该能够修复它。(请让 getXX 函数返回一个值,如果他们不命名他们 setXX 并让他们将他们的结果写入对象变量......)
- 1 回答
- 0 关注
- 118 浏览
添加回答
举报
0/150
提交
取消