...

View Full Version : Variable in array help..



tkaeer
01-08-2010, 09:46 PM
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:


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:


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 :)

Fou-Lu
01-08-2010, 10:33 PM
$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:


$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.";
}

tkaeer
01-08-2010, 11:29 PM
$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:


$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! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum