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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    whts wrong with this Code..

    Hello

    i have this code Bellow . where i want the Value of $all to be filed under Value $do .

    PHP Code:
     $all"1""2""3""yes""no""off""sure""ok""mode""or";
     
    $do = array("$all"); 
    whts wrong in that Code ..

    PS : i do not want the Values be direct under do like
    PHP Code:
    $do = array("1""2""3""yes""no""off""sure""ok""mode""or"); 
    i know that works but i do not want use it that way to avoid duplicate

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Is $do an empty array at the start? If so then just do it the second way, if not try this:

    PHP Code:
    array_push($do"1""2""3""yes""no""off""sure""ok""mode""or"); 

    Edit: do you mean you want to create an array with no duplicate entries? If so take a look at the array_unique function

  • Users who have thanked Mwnciau for this post:

    ajloun (08-28-2009)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    First, fix up that $all, it should be a complete string:
    PHP Code:
     $all'"1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or"'
    Once fixed, use explode:
    PHP Code:
    $do explode(', '$all); 
    All done.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    ajloun (08-28-2009)

  • #4
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    umm Maybe i was not Clear ..

    I want the Valuse of $all fill as is in the $do

    i tried this.
    PHP Code:
    $all="1,2,3,4,on,yes"
        
    $do=explode(",",$all); 
    but didt work , show no error thu

  • #5
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    i answered before read Fou answer , I tried that but for some reason the value of $all won't be in do when do ur way ..

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by onasre View Post
    Hello

    i have this code Bellow . where i want the Value of $all to be filed under Value $do .

    PHP Code:
     $all"1""2""3""yes""no""off""sure""ok""mode""or";
     
    $do = array("$all"); 
    whts wrong in that Code ..

    PS : i do not want the Values be direct under do like
    PHP Code:
    $do = array("1""2""3""yes""no""off""sure""ok""mode""or"); 
    i know that works but i do not want use it that way to avoid duplicate
    You specified that you want each of the items in the string $all to be an item in array $do.
    If you just want it to be a single offset in $do, than you can use:
    PHP Code:
    $all'"1", "2", "3", "yes", "no", "off", "sure", "ok", "mode", "or"';
    $do = (array)$all
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Ok Sorry for not been Clear , i will try again my Best Now i have This Code .
    PHP Code:
    $do= array("1""2""3""yes""no""off""sure""ok""mode""or"); 
    I do not want keep write this Code when every needed so i Need it look like
    PHP Code:
    $all= array("$do"); 
    where $all Means the valuse "1","2"....etc

    wht is the right way to do it

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Than its explode you want:
    PHP Code:
    $all "1,2,3,4,on,yes";
    $do explode(','$all);
    print_r($do); 
    Results:
    Code:
    Array
    (
        [0] => 1,
        [1] => 2,
        [2] => 3,
        [3] => 4,
        [4] => on,
        [5] => yes
    )
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    ajloun (08-28-2009)

  • #9
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Thx Fou .. i went with the other Soluation you Gave me first


  •  

    Posting Permissions

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