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

后端 未结 6 1744
清酒与你
清酒与你 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 08:54

    Nope, it is not possible.

    Try this:

    file.php?foo=bar

    file.php contents:

    
    

    You get

    Array
    (
        [foo] => bar
    )
    

    If you want to access the element at 0, try file.php?0=foobar.

    You can also use a foreach or for loop and simply break after the first element (or whatever element you happen to want to reach):

    foreach($_GET as $value){
        echo($value);
        break;
    }
    

提交回复
热议问题