Can items in PHP associative arrays not be accessed numerically (i.e. by index)?

后端 未结 6 1762
清酒与你
清酒与你 2021-01-06 08:26

I\'m trying to understand why, on my page with a query string, the code:

echo \"Item count = \" . count($_GET);
echo \"First item = \" . $_         


        
6条回答
  •  感动是毒
    2021-01-06 09:12

    Yes, the key of an array element is either an integer (must not be starting with 0) or an associative key, not both.

    You can access the items either with a loop like this:

    foreach ($_GET as $key => $value) {
    }
    

    Or get the values as an numerical array starting with key 0 with the array_values() function or get the first value with reset().

提交回复
热议问题