How to add an array value to the middle of an associative array?

前端 未结 13 1642
余生分开走
余生分开走 2020-12-08 00:36

Lets say I have this array:

$array = array(\'a\'=>1,\'z\'=>2,\'d\'=>4);

Later in the script, I want to add the value \'c\'=>3<

13条回答
  •  一向
    一向 (楼主)
    2020-12-08 01:30

    Great usage of array functions but how about this as a simpler way:

    Add a static column to the SQL and then replace it in the resultant array. Order stays the same:

    SQL :

    Select pizza , drink , 'pizza-drink' as 'pizza-drink' , 28 columns..... From Table
    

    Array :

    $result['pizza-drink'] = $result['pizza'] . $result['drink'];
    

提交回复
热议问题