accessing array data inside of an array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bill

    #1

    accessing array data inside of an array

    I want to extract the name of the photo uploaded.

    print_r of $_FILES yields:
    Files: Array ( [picture] =Array ( [name] =>
    DSC_1802-saoirse-riona.jpg [type] =image/jpeg [tmp_name] =>
    /tmp/phpJTspHZ [error] =0 [size] =76096 ) )

    so we have an array with one element, picture, that contains an
    array with an index, name, with a value of DSC_1802-saoirse-riona.jpg

    I get the correct value when I:
    $pic_name = $_FILES['picture']['name'];
    echo $pic_name

    however when I use:

    echo "<br />pic_name = $_FILES[picture][name]";

    I get:
    pic_name = Array[name]

    Why does the echo with the array reference not work while the
    assignment does ?

    bill
  • ZeldorBlat

    #2
    Re: accessing array data inside of an array

    On Nov 18, 10:13 am, bill <nob...@spamcop .netwrote:
    I want to extract the name of the photo uploaded.
    >
    print_r of $_FILES yields:
    Files: Array ( [picture] =Array ( [name] =>
    DSC_1802-saoirse-riona.jpg [type] =image/jpeg [tmp_name] =>
    /tmp/phpJTspHZ [error] =0 [size] =76096 ) )
    >
    so we have an array with one element, picture, that contains an
    array with an index, name, with a value of DSC_1802-saoirse-riona.jpg
    >
    I get the correct value when I:
    $pic_name = $_FILES['picture']['name'];
    echo $pic_name
    >
    however when I use:
    >
    echo "<br />pic_name = $_FILES[picture][name]";
    >
    I get:
    pic_name = Array[name]
    >
    Why does the echo with the array reference not work while the
    assignment does ?
    >
    bill
    Put quotes around your array keys:

    $_FILES['picture']['name']

    Comment

    • bill

      #3
      Re: accessing array data inside of an array

      ZeldorBlat wrote:
      On Nov 18, 10:13 am, bill <nob...@spamcop .netwrote:
      >I want to extract the name of the photo uploaded.
      >>
      >print_r of $_FILES yields:
      >Files: Array ( [picture] =Array ( [name] =>
      >DSC_1802-saoirse-riona.jpg [type] =image/jpeg [tmp_name] =>
      >/tmp/phpJTspHZ [error] =0 [size] =76096 ) )
      >>
      >so we have an array with one element, picture, that contains an
      >array with an index, name, with a value of DSC_1802-saoirse-riona.jpg
      >>
      >I get the correct value when I:
      >$pic_name = $_FILES['picture']['name'];
      >echo $pic_name
      >>
      >however when I use:
      >>
      >echo "<br />pic_name = $_FILES[picture][name]";
      >>
      >I get:
      >pic_name = Array[name]
      >>
      >Why does the echo with the array reference not work while the
      >assignment does ?
      >>
      >bill
      >
      Put quotes around your array keys:
      >
      $_FILES['picture']['name']
      That, unfortunately, generates the dreaded:
      Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE,
      expecting T_STRING or T_VARIABLE or T_NUM_STRING in...

      bill

      Comment

      • Rik Wasmus

        #4
        Re: accessing array data inside of an array

        On Sun, 18 Nov 2007 16:47:17 +0100, bill <nobody@spamcop .netwrote:
        ZeldorBlat wrote:
        >On Nov 18, 10:13 am, bill <nob...@spamcop .netwrote:
        >>I want to extract the name of the photo uploaded.
        >>>
        >>print_r of $_FILES yields:
        >>Files: Array ( [picture] =Array ( [name] =>
        >>DSC_1802-saoirse-riona.jpg [type] =image/jpeg [tmp_name] =>
        >>/tmp/phpJTspHZ [error] =0 [size] =76096 ) )
        >>>
        >>so we have an array with one element, picture, that contains an
        >>array with an index, name, with a value of DSC_1802-saoirse-riona.jpg
        >>>
        >>I get the correct value when I:
        >>$pic_name = $_FILES['picture']['name'];
        >>echo $pic_name
        >>>
        >>however when I use:
        >>>
        >>echo "<br />pic_name = $_FILES[picture][name]";
        >>>
        >>I get:
        >>pic_name = Array[name]
        >>>
        >>Why does the echo with the array reference not work while the
        >>assignment does ?
        >>>
        >>bill
        > Put quotes around your array keys:
        > $_FILES['picture']['name']
        >
        That, unfortunately, generates the dreaded:
        Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE,
        expecting T_STRING or T_VARIABLE or T_NUM_STRING in...
        Look at complex (curly) syntax:
        <http://nl2.php.net/manual/en/language.types. string.php#lang uage.types.stri ng.parsing>

        echo "<br />pic_name = {$_FILES['picture']['name']}";


        --
        Rik Wasmus

        Comment

        • Toby A Inkster

          #5
          Re: accessing array data inside of an array

          bill wrote:
          echo "<br />pic_name = $_FILES[picture][name]";
          echo "<br />pic_name = {$_FILES[picture][name]}";

          --
          Toby A Inkster BSc (Hons) ARCS
          [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
          [OS: Linux 2.6.12-12mdksmp, up 12 days, 2 min.]
          [Now Playing: ./orson/bright_idea/03_-_happiness.ogg.]

          USD/EUR Exchange Rate Graph

          Comment

          • Rik Wasmus

            #6
            Re: accessing array data inside of an array

            On Sun, 18 Nov 2007 18:05:32 +0100, Toby A Inkster
            <usenet200707@t obyinkster.co.u kwrote:
            bill wrote:
            >
            >echo "<br />pic_name = $_FILES[picture][name]";
            >
            echo "<br />pic_name = {$_FILES[picture][name]}";
            >
            define('picture ','oops');
            define('name',' wrong');
            --
            Rik Wasmus

            Comment

            • Toby A Inkster

              #7
              Re: accessing array data inside of an array

              Rik Wasmus wrote:
              define('picture ','oops');
              define('name',' wrong');
              I know, I know, but I wanted to keep the code as similar as possible to
              the OP's.

              Besides which, it's not normal to define lower-case constants.

              --
              Toby A Inkster BSc (Hons) ARCS
              [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
              [OS: Linux 2.6.12-12mdksmp, up 12 days, 15:31.]

              USD/EUR Exchange Rate Graph

              Comment

              • Toby A Inkster

                #8
                Re: accessing array data inside of an array

                Toby A Inkster wrote:
                Besides which, it's not normal to define lower-case constants.
                And people who do so are not normal. They have something wrong with them
                in their head. Just thinking about the idea makes me feel icky.

                --
                Toby A Inkster BSc (Hons) ARCS
                [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
                [OS: Linux 2.6.12-12mdksmp, up 12 days, 17:44.]

                USD/EUR Exchange Rate Graph

                Comment

                • bill

                  #9
                  Re: accessing array data inside of an array

                  Toby A Inkster wrote:
                  bill wrote:
                  >
                  >echo "<br />pic_name = $_FILES[picture][name]";
                  >
                  echo "<br />pic_name = {$_FILES[picture][name]}";
                  >
                  Rik and Toby
                  Thanks, something new to learn.

                  bill

                  Comment

                  • Rik Wasmus

                    #10
                    Re: accessing array data inside of an array

                    On Mon, 19 Nov 2007 09:34:23 +0100, Toby A Inkster
                    <usenet200707@t obyinkster.co.u kwrote:
                    Rik Wasmus wrote:
                    >define('pictur e','oops');
                    >define('name', 'wrong');
                    >
                    I know, I know, but I wanted to keep the code as similar as possible to
                    the OP's.
                    Then again, why correct just one mistake and not the other?
                    Besides which, it's not normal to define lower-case constants.
                    Very true indeed.
                    --
                    Rik Wasmus

                    Comment

                    Working...