SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    158
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    iterate through array and get pull out specific values

    Hello,

    I'm trying to pull 2 specific values from the array below, the "name" & the "tmp_name":

    array(5) { ["name"]=> array(1) { [0]=> string(10) "orange.jpg" } ["type"]=> array(1) { [0]=> string(10) "image/jpeg" } ["tmp_name"]=> array(1) { [0]=> string(14) "/tmp/phpzVAl3n" } ["error"]=> array(1) { [0]=> int(0) } ["size"]=> array(1) { [0]=> int(13748) } }

    I tried different variations with the foreach loop and I'm not getting the results i'm looking to get.
    any ideas on how i can pull the 2 values out? in this case $v1= "orange.jpg" and $v2="/tmp/phpzVAl3n"

    PHP Code:
    foreach($testArray as $key1 => $value)
    {    if(
    is_array($value)) 
        {    foreach (
    $value as $key2 => $val2
            {    echo 
    $key1 ." "$key2" "$val2; }  
        }


  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Is the array shown still in the $_FILES array or has it been moved out of the $_FILES array?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    $v1 = $array['name'][0];
    $v2 = $array['tmp_name'][0];
    ... you... really dont need to loop anything here?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    158
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    Is the array shown still in the $_FILES array or has it been moved out of the $_FILES array?

    Thanks for the looking at my posting.

    its moved into $testArray. having said that if you have a different idea I'm open to looking at it. it would take much to change my test code round.

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    158
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    $v1 = $array['name'][0];
    $v2 = $array['tmp_name'][0];
    ... you... really dont need to loop anything here?
    Hi StarLion,
    Thank you for the help.
    I rewrote the code with your suggestion and still not able to get seprate the 2 specific values i need. I copy/pasted the rewrite and the results.
    How can I just get the 2 values?
    PHP Code:
    foreach($testArray as $key1 => $value)
    {     if(
    is_array($value)) 
        {   echo 
    $valA $testArray['name'][0];
                echo 
    "<br>";
                echo 
    $valB $testArray['tmp_name'][0];                  
        }

    resutls:
    geo1.JPG
    /tmp/phpvhk268geo1.JPG
    /tmp/phpvhk268geo1.JPG
    /tmp/phpvhk268geo1.JPG
    /tmp/phpvhk268geo1.JPG
    /tmp/phpvhk268

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    It's impossible for you to have gotten these results with just the code you pasted there, unless you're looping through this whole code block more than once. the value of $testArray['name'][0] would not change. Please show us the WHOLE code.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •