我对函数的实现一定有一些误解,$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()函数生成。
<?php
class 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!";
}
}
阿波罗的战车