The function below was contrived to fetch a .csv file, read down a column and turn its values into an array. Then if $category - in this case "printers" - occurs in the array, return "shipping-for-medium-sized-goods";.
function get_ship_class($category){
$csv = array_map("str_getcsv", file("https://siliconharvest.com.au/cassius-files/Shipping%20Classes.csv", "r"));
$header = array_shift($csv);
// Seperate the header from data
$col = array_search("medium_shipping_class", $header);
// Pass the extracted column back to calling method
return array_column($csv,$col);
if ( in_array( $category, get_ship_class() )) {
return "shipping-for-medium-sized-goods";
}
}
I then run the function:
get_ship_class("printers");
// Note you can access the CSV file at that URL in the function above;
// See that"printers" is a value that occurs in the "medium_shipping_class" column
// Therefore we have a match for if ( in_array( $category = "printers", get_ship_class() ))
Yet, I get the error:
Warning: file() expects parameter 2 to be integer, string given in /home/ptrcao/public_html/siliconharvest/wp-content/uploads/wpallimport/functions.php on line 147
Warning: array_map(): Argument #2 should be an array in /home/ptrcao/public_html/siliconharvest/wp-content/uploads/wpallimport/functions.php on line 147
Warning: array_shift() expects parameter 1 to be array, null given in /home/ptrcao/public_html/siliconharvest/wp-content/uploads/wpallimport/functions.php on line 148
Warning: array_search() expects parameter 2 to be array, null given in /home/ptrcao/public_html/siliconharvest/wp-content/uploads/wpallimport/functions.php on line 151
Warning: array_column() expects parameter 1 to be array, null given in /home/ptrcao/public_html/siliconharvest/wp-content/uploads/wpallimport/functions.php on line 154
file! php.net/manual/en/function.file.php The second parameter you are passing to this function here clearly makes no sense.