Add 2 values to 1 key in a PHP array

后端 未结 7 1026
面向向阳花
面向向阳花 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:14

    You could use two separate arrays, maybe like:

    $values_names = array();
    $values_initials = array();
    array_push($values_names, 'Mike');
    array_push($values_initials, 'M');
    array_push($values_names, 'Tom');
    array_push($values_initials, 'T');
    array_push($values_names, 'Jim');
    array_push($values_initials, 'J');
    

    So you use two arrays, one for each of the second and third columns using the values in the first one as keys for both arrays.

提交回复
热议问题