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 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2009
    Location
    Sweden
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Variable in array help..

    Hey!
    I'm trying to put a variable in my array I have but it doesn't work ..

    Here is my script with a variable:
    PHP Code:
    while($idet mysql_fetch_array($q_rostning)){
    $namnen = array($idet['Namn']);
    if (!
    in_array("tkaeer"$namnen)){ 
    And this will not work for me ..

    Here is my script with some random data:
    PHP Code:
    while($idet mysql_fetch_array($q_rostning)){
    $namnen = array("tkaeer""randomname""anotherrandomname");
    if (!
    in_array("tkaeer"$namnen)){ 
    Is there possible to to this kind of thing?

    /Tkaeer
    Last edited by tkaeer; 01-08-2010 at 09:50 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    $namnen will only ever be a 1 element array since you always overwrite it.
    To me, it looks like check for in array should also be outside of the while loop:
    PHP Code:
    $namnen = array();
    while (
    $idet mysql_fetch_array($q_rostning))
    {
        
    $namnen[] = $idet['Namn'];
    }

    if (!
    in_array("tkaeer"$namnen)) // Or it could be a variable or whatever.
    {
        print 
    "That name is not in the list.";

    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Dec 2009
    Location
    Sweden
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    $namnen will only ever be a 1 element array since you always overwrite it.
    To me, it looks like check for in array should also be outside of the while loop:
    PHP Code:
    $namnen = array();
    while (
    $idet mysql_fetch_array($q_rostning))
    {
        
    $namnen[] = $idet['Namn'];
    }

    if (!
    in_array("tkaeer"$namnen)) // Or it could be a variable or whatever.
    {
        print 
    "That name is not in the list.";


    Thanx!, Really helped me!


  •  

    Posting Permissions

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