Professional Web Applications Themes

How to access second element of the array $_REQUEST? - PHP Development

Hello, How to access second element of $_REQUEST? I tried echo $_REQUEST[2] and got nothing, but when i check p[rint_r($_REQUEST) then I see the array has surely more than 3 elements. Regards, Talthen...

  1. #1

    Default How to access second element of the array $_REQUEST?

    Hello,
    How to access second element of $_REQUEST?

    I tried echo $_REQUEST[2] and got nothing, but when i check

    p[rint_r($_REQUEST) then I see the array has surely more than 3 elements.

    Regards,

    Talthen


    Guest

  2. #2

    Default Re: How to access second element of the array $_REQUEST?

    pl wrote: 

    $_REQUEST is not an indexed array, but associative. This means that values
    can only be retrieved by keys.

    Example:

    The page is requested with a parameter foo with the value bar, as in:
    page.php?foo=bar

    If you want to print 'bar', you should do it like this:

    print $_REQUEST['foo'];

    But, you can get the values of the an associative array as an indexed array
    through the array_values function:

    $values = array_values($_REQUEST);

    Afterwhich you can retrieve the values by their index:

    print $value[1]; // 1 is the second index as 0 is always the first index

    Please have a close look at the online manual starting at
    http://www.php.net/manual/en/index.php to prevent asking basic questions
    like this in the future.


    JW



    Janwillem Guest

  3. #3

    Default Re: How to access second element of the array $_REQUEST?

    "Janwillem Borleffs" <com> 

    Well... I thought it is both associative and indexed (like the $array
    =mysql_fetch_rows which can be "BOTH").
     
    Ok, thx.

    Regards,
    Talthen


    Guest

  4. #4

    Default Re: How to access second element of the array $_REQUEST?

    On Sat, 6 Aug 2005 12:58:25 +0200, "Janwillem Borleffs" <com>
    wrote:
     

    Although to be picky, PHP associative arrays do preserve key ordering
    (e.g.compare with Perl hashes, which don't), so there is a "value associated
    with the second key", at least.

    <?php
    $a = array(
    'a' => 'z',
    'b' => 'y',
    'c' => 'x'
    );

    $k = array_keys($a);
    print $a[$k[1]];
    ?>

    It seems possibly a bit dodgy to apply in relation to $_REQUEST since that can
    be populated in various ways, not of which have ordering guarantees that I'm
    sure enough about.

    --
    Andy Hassall / <co.uk> / <http://www.andyh.co.uk>
    <http://www.andyhsoftware.co.uk/space> Space: disk usage ysis tool
    Andy Guest

  5. #5

    Default Re: How to access second element of the array $_REQUEST?

    On Sat, 6 Aug 2005 12:58:25 +0200, "Janwillem Borleffs" <com>
    wrote:
     

    [ Just in case my previous reply that I've just sent a cancel message for gets
    through - ignore it, I obviously only read half the post :p ]

    --
    Andy Hassall / <co.uk> / <http://www.andyh.co.uk>
    <http://www.andyhsoftware.co.uk/space> Space: disk usage ysis tool
    Andy Guest

Similar Threads

  1. Replies: 0
    Last Post: July 22nd, 04:11 PM
  2. #24565 [Com]: cannot read array elements recived via $_REQUEST
    By vma1 at abv dot bg in forum PHP Development
    Replies: 2
    Last Post: July 22nd, 10:16 AM
  3. #24565 [Opn->Ver]: cannot read array elements recived via $_REQUEST
    By sniper@php.net in forum PHP Development
    Replies: 0
    Last Post: July 9th, 09:01 PM
  4. #24565 [NEW]: cannot read array elements recived via $_REQUEST
    By nightcat at poczta dot onet dot pl in forum PHP Development
    Replies: 0
    Last Post: July 9th, 04:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139