【发布时间】:2018-10-27 01:19:22
【问题描述】:
我有一系列对象,对于每个对象,我都有名称、类别、价格和其他一些东西。并从该数组中删除具有特定类别的对象。
public function getCSV()
{
$contents = Storage::disk('dropbox')->get('InventoryReport.csv');
$lines = explode(PHP_EOL, $contents);
$items = array();
// categories to ignore when importing
$ignore = ['Misc', 'Soft Drinks', 'Juices', 'Water', 'Snack', 'Energy Drink', 'Tobacco', 'Gum', 'Account Payment'];
foreach ($lines as $line)
{
$items[] = str_getcsv($line);
}
array_shift($items);
array_pop($items);
// foreach ($items as $item)
// {
// $i = Item::where('upc', $item[7])->first();
// if($i == null)
// {
// $name = str_slug($item[8], '-');
// // $inventory = Item::create(
// // ['upc' => $item[7],
// // 'name' => $item[8],
// // 'price' => $item[9],
// // 'stock' => $item[10],
// // 'cost' => $item[11],
// // 'category' => $item[2],
// // 'slug' => $name
// // ]
// // );
// }
// }
}
以上是我的代码。我想删除数组中具有 $ignore 数组中的类别的所有项目。在我将其存储到数据库之前。
【问题讨论】: