php非法字符串偏移,php - Laravel按数组分组-非法字符串偏移 - 堆栈内存溢出

我已经将一个csv文件转换为数组,并使用一些键将数组数据分组。 我定义了一个groupBy函数来处理数组数据。 但是,我遇到了这个错误,不确定哪一部分出错了。

代码:groupby函数

public function group($key, $item) {

$result = array();

foreach($item as $val) {

$result[$val[$key]][] = $val;

}

return $result;

}

数据转换功能。

public function saveNewSale()

{

foreach (array_chunk($items, $chunk_size) as $chunk) {

$cleaned_items = [];

foreach ($chunk as $item) {

//Data Transformation

//call groupby function

$byGroup = $this->group('ref_num', $item);

array_push($cleaned_items, $item);

}

这是我的数组

array:2 [

0 => array:13 [

"ref_num" => "INV699"

"payment_term" => array:2 [

"id" => 1

"name" => "Cash"

]

"items" => array:1 [

0 => array:8 [

"code" => "3MVR0003"

"description" => "3M Vinyl

"tax_value" => 0.06

"qty" => 1

"unit" => 1

"price" => 10

"total" => 212

"total_tax" => 12

]

]

"terms" => array:1 [

0 => array:2 [

"date" => "2019-02-20"

"amount" => 200

]

]

]

1 => array:13 [

"ref_num" => "INV699"

"payment_term" => array:2 [

"id" => 1

"name" => "Cash"

]

"items" => array:1 [

0 => array:8 [

"code" => "sony"

"description" => "3xperia"

"tax_value" => 0.06

"qty" => 1

"unit" => 1

"price" => 10

"total" => 212

"total_tax" => 12

]

]

"terms" => array:1 [

0 => array:2 [

"date" => "2019-02-20"

"amount" => 200

]

]

]

]

我需要基于ref_num将这两个数组ref_num 。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值