Are numeric and associative arrays in PHP in two different ways?

This is a deeper immersion in the previous question I had here: Can't access elements in PHP associative arrays numerically (i.e. by index)?

According to W3Schools:

There are three types of arrays in PHP:

  • Numeric Array - An array with a numerical index
  • Associative array - an array in which each identification key is associated with a value
  • Multidimensional array - an array containing one or more arrays

But is that for sure? Each element of the array can be assigned either an index or a string as a key - so what happens when two are mixed in the same array?

$myArray[0] = 'value1';
$myArray['one'] = 'value2';
+3
source share
4 answers

PHP ; -, , .

Manual:

PHP, , .

, , . "" .

Wikipedia:

- , , ( ).

...

. () , . , Python, .

PHP, .

+6

PHP . . . .

( "123" . PHP .)

, ArrayObject. , .

+6

, , W3Schools.

, , , .

, W3Schools, .

  • -

, - . , , ( , . ) , .

  • - , .

. , , .

  • . , . . .

, .

, ( ) . .

$arr = array(
 '1' => 'abc',
 2 => 'def'
);

var_dump($arr);

array(2) {
  [1]=>
  string(3) "abc"
  [2]=>
  string(3) "def"
}
+4

. :

$myArray[0] = 'value1';
$myArray['one'] = 'value2';

echo($myArray[1]);

? .

0

All Articles