0

ループ内で結果の配列を生成しており、ループ内で配列に追加したいと考えています。これらはキーと値のペアであるため、明らかに配列のプッシュは機能しません。

foreach($res as $ap){
    $this->db->where('event_time >', $ev_time);
    $this->db->where('event_ID', $ap['event_id']);
    $query = $this->db->get('events');
    if($query->num_rows() > 0){
        $result = $query->result_array();
        $linked[] = $result[0]; // <-- want to add key, value pair within this
        $linked['new_key'] = $new_value; // <-- did not work :(
    }
}

これどうやってするの?

また、この配列は後で別の配列とマージされます。他の配列にない余分なキーと値のペアをこれに追加すると、マージが壊れますか?

4

3 に答える 3

0
foreach($res as $ap){
    $this->db->where('event_time >', $ev_time);
    $this->db->where('event_ID', $ap['event_id']);
    $query = $this->db->get('events');
    if($query->num_rows() > 0){
        $result = $query->result_array();
        $linked[] = $result[0]; // <-- want to add key, value pair within this

        $linked['new_key'][] = $new_value;
    }
}
于 2013-10-10T11:13:16.857 に答える