Get the App
SLTechnology News&Howtos  ›  Development  › 

Why is the result of php array array ("a") + array ("b") still array ("a")

Shulou Source: shulou.com Published: 2022-06-03 18:59:56 10月03日 Update

This article introduces the "php array array (" a ") + array (" b ") why the result is still array (" a ") related knowledge, in the actual case operation process, many people will encounter such a dilemma, then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

I saw a question on the Internet:

The result of array ("a") + array ("b") is _ _

A.array ("a", "b")

B.array ("b", "a")

C.array ("b")

D.array ("a")

Answer: d

When the two arrays of php are added together, why does the result remain the same?

Because they are equivalent to array ("0" = > "a") + array ("0" = > "b"), they have the same key name, and the former cannot be overwritten by the latter. If it is array ("0" = > "a") + array ("0" = > "b", "1" = > "c"), then the result is equal to array ("0" = > "a", "1" = > "c").

What happens if you have the same key name in the same array?

Take a look at the code in the official php manual:

The copy code is as follows:

$switching = array (10, / / key = 0

5 = > 6

3 = > 7

'a'= > 4

11, / / key = 6 (maximum of integer-indices was 5)

'8' = > 2, / / key = 8 (integer!)

'02' = > 77, / / key =' 02'

0 = > 12 / / the value 10 will be overwritten by 12

);

It can be seen that if there is the same key name in the same array, the value of the previous key name will be overwritten (overwritten).

"php array array (" a ") + array (" b ") why the result is still array (" a ") is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Array result or same code content situation more knowledge utility learning and then one two dilemma official actual manual article case. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno Shulou Information NVidia Redmi