Add 2 values to 1 key in a PHP array

后端 未结 7 1014
面向向阳花
面向向阳花 2021-02-08 03:35

I have a result set of data that I want to write to an array in php. Here is my sample data:

**Name** **Abbrev**
Mike     M
Tom      T
Jim      J
7条回答
  •  攒了一身酷
    2021-02-08 04:09

    $person = array('name' => 'Mike', 'initial' => 'M');
    array_push($people, $person);
    

    That said, I'm not sure why you're storing the data separately. The initial can be fetched directly from the name via substr($name, 0, 1).

提交回复
热议问题