Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: array

  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts

    array

    I'm trying to pass an array from one page to another and display it's contents on the next page.

    This is the code I am using

    PHP Code:
    $var1 $_GET["name"]; 

    foreach(
    $var1 as $value

       echo 
    $value
    I keep getting this error "Warning: Invalid argument supplied for foreach() in..\..\..\..\..."

    Any ideas?

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    PHP Code:
    $var1 $_GET["name"]; 
    are u sure $var1 is an array?

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i passed an array in the form action of a form using this line

    "deleted.php?name=$array"

    where $array is an array in the page it is sent from

    is it possible to send an array this way
    and is there a way of checking if it is an array on the pg it is sent to?

    foreach is not working for me

    thanks

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Doing this:

    PHP Code:
    $array = array(1434);
    $url "index.php?array=".$array;
    echo 
    $url
    Will not work. You cannot pass an array that way.

    You should consider using sessions, or perhaps try this depending on what is in the array:

    Page 1:
    PHP Code:
    $array = array(1434);
    $url "index.php?array=".urlencode(implode(', '$array));
    echo 
    $url
    index.php
    PHP Code:
    $array explode(','urldecode($_GET['array'])); 

  • #5
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    http requests are sent as text not as php objects...

    Code:
    "deleted.php?name=" . implode(',', $array)
    and when u get it back
    Code:
    $var1 = $_GET["name"]; 
    $arr  = explode(',', $array);
    foreach should now work on $arr


  •  

    Posting Permissions

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