PHP array_push不带数字键 [英] PHP array_push without numeric key

查看:134
本文介绍了PHP array_push不带数字键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用数字键的情况下推送新数组?

how do i push new array without numeric key?

$array = array('connect' => array('mydomain.com' => 1.99) );
$new_array['mynewdomain.com'] = 2.99;

array_push($array['connect'], $new_array);

当前返回:

Array
(
    [connect] => Array
        (
            [mydomain.com] => 1.99
            [0] => Array
                (
                    [mynewdomain.com] => 2.99
                )
        )
)

https://ideone.com/VgL67Y

我期望以下输出:

Array
(
    [connect] => Array
        (
            [mydomain.com] => 1.99
            [mynewdomain.com] => 2.99
        )
)

推荐答案

只需将元素追加到数组.

Simply append element to the array.

$array['connect']['mynewdomain.com'] = 2.99;

无需执行array_push().只需使用PHP的内置结构即可完成工作.

No need to do array_push(). Just use PHP's in built constructs to get the job done.

与内置函数和自定义函数相比,内置语言构造的速度更快.

In Built language constructs are more faster than in built functions and custom functions.

这篇关于PHP array_push不带数字键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆