Push item to associative array in PHP

后端 未结 12 1409
野趣味
野趣味 2020-12-04 22:47

I\'ve been trying to push an item to an associative array like this:

$new_input[\'name\'] = array(
    \'type\' => \'text\', 
    \'label\' => \'First          


        
12条回答
  •  执笔经年
    2020-12-04 23:38

    This is a cool function

    function array_push_assoc($array, $key, $value){
       $array[$key] = $value;
       return $array;
    }
    

    Just use

    $myarray = array_push_assoc($myarray, 'h', 'hello');
    

    Credits & Explanation

提交回复
热议问题