Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$a = [];
$a['8'] = 'x';
$a[8] = 'y';
$a['08'] = 'z';
$a[] = 'w';
echo count($a), ' ', implode(' ', array_keys($a)), "\n";3 8 08 9
- Expecting
'8'and8to be two separate keys: a string holding a plain decimal integer is cast toint, so$a[8] = 'y'overwrites the value under'8'. - Expecting
$a[]to add the element at indexcount($a): the next index is the largest integer key plus one, here9, however many elements there are.
- Which key do
$a[true] = 'v'and$a['1'] = 'v'write to? - Which index does the next
$a[]get afterunset($a[9])?