Home » Php » arrays – PHP array_push without numeric key

# arrays – PHP array_push without numeric key

Questions:

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);
``````

Currently returning:

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

https://ideone.com/VgL67Y

i am expecting the following output:

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

Simply append element to the array.

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

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.

Use `+` for this. Try with –
``````\$array = array('connect' => array('mydomain.com' => 1.99) );
``````\$array['connect'] = array_merge(\$array['connect'], \$new_array);
{"ft_lang_label":"__label__en","ft_lang_prob":0.5239773,"math_prob":0.68456465,"size":926,"snap":"2020-45-2020-50","text_gpt3_token_len":274,"char_repetition_ratio":0.19197397,"word_repetition_ratio":0.15503876,"special_character_ratio":0.35529158,"punctuation_ratio":0.21556886,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97509056,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-04T02:01:25Z\",\"WARC-Record-ID\":\"<urn:uuid:cf428dea-736e-4f2a-a1f1-e79d38b5e023>\",\"Content-Length\":\"51892\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:38a0eafc-eafe-4381-88e5-986979a653c8>\",\"WARC-Concurrent-To\":\"<urn:uuid:d16f4516-7a58-46df-9735-506668322068>\",\"WARC-IP-Address\":\"104.31.94.169\",\"WARC-Target-URI\":\"https://exceptionshub.com/arrays-php-array_push-without-numeric-key.html\",\"WARC-Payload-Digest\":\"sha1:TARKD5MTJYRAI5YWKSZEZTWY5SEQEZ5Y\",\"WARC-Block-Digest\":\"sha1:PA4FHEYMZFV27YDINN2DBEPICLGVESIT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141733120.84_warc_CC-MAIN-20201204010410-20201204040410-00575.warc.gz\"}"}