duanlv5084
2016-06-02 17:56
浏览 60
已采纳

Codeigniter:向数组添加新项

I'm creating a large array of info ready to be exported as a csv.

I'm having trouble adding additional items to the array.

I've looked at the php manual and loads of other resources, but I'm unable to get it to work?

All the work is done in my controller

public function payments_export()
    {
        $parents = $this->Swim_model->CRUD_read_parents();
        foreach ($parents->result() as $parentsrow)
        {
            if($parentsrow->AdultID > 1000010)
            {
            $data[] = array(
                'First Name' => $parentsrow->AdultFirstName,
                'Surname' => $parentsrow->AdultLastName,
                'Email' => $parentsrow->EmailName,
            );

Lots more processing to produce $owes

                $owes = number_format(array_sum($children) - $autodiscount, 2);
                if($owes != 0)
                {
                $data['Fees'] = $owes;
                }
            }
        }

So I create the array $data and store three bits of info in it - lots of processing later produces $owes (which is correct), but when I try to add it to the same row in the array, it doesn't?

The foreach loop should then go through each parent and add another row to the array containing the four items on each row.

图片转代码服务由CSDN问答提供 功能建议

我正在创建一大堆信息,可以将其导出为csv。 \ n

我在向阵列中添加其他项目时遇到了麻烦。

我查看了php手册和其他资源的加载,但我无法得到它 工作?

所有工作都在我的控制器中完成

  public function payments_export()
 {
 $ parents = $ this  - > Swim_model-> CRUD_read_parents(); 
 foreach($ parents-> result()as $ parentsrow)
 {
 if if($ parentsrow-> AdultID> 1000010)
 {
 $  data [] = array(
'First Name'=> $ parentsrow-> AdultFirstName,
'姓氏'=> $ parentsrow-> AdultLastName,
'电子邮件'=> $ parentsrow->  EmailName,
); 
   
 
 

产生$ owes的更多处理

  $ owes = number_format(array_sum  ($ children) -  $ autodiscount,2); 
  if($ owes!= 0)
 {
 $ data ['Fees'] = $ owes; 
} 
} 
} 
   
 
 

所以我创建了数组$ data并在其中存储了三位信息 - 许多处理后来产生$ owes(这是正确的),但是当我尝试将它添加到数组中的同一行时,它不会?

然后,foreach循环应遍历每个父级,并将另一行添加到包含每行上四个项目的数组中。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题