Jump to content

[SOLVED] Need some help with arrays


CSmith1128

Recommended Posts

Hello. I need some help with arrays. I am trying to get the contents of a file and put them into an array.

I have everything working so far, except when I want to compare the contents of an element in an array with another variable.

 

The other variable is coming from a session.

 

So i have something like this.

 

$num1 = $_SESSION['num1'];

 

and i have an array set with data from the text file..

 

Now i want to see if($array1[0] == $num1).

 

When they are equal to eachother, I want to display "ok".

 

So everything should work, and I know the two equal eachother, but it never says they are equal.

 

When I set $num1 = 1; they say they are the same, but when i use the sessions it never says they are the same, but I know they are.

 

Could someone help me figure this out?

 

Thanks,

Chris

Link to comment
https://forums.phpfreaks.com/topic/50323-solved-need-some-help-with-arrays/
Share on other sites

yea sorry.. here is the code i am using...

 

$num1 = $_SESSION['num1'];

$array1= array();

$array2= array();

$x = 0;

$fileName = "file.txt";

$handle = fopen($fileName, 'r');

while (!feof($handle))

{

$array1[$x] = fgets($handle);

$array2[$x] = fgets($handle);

$x++;

}

 

fclose($handle);

 

if($num1 == $array1[0])

{

echo "ok";

}

 

//----------------------------------------------------------------------

//----------------------------------------------------------------------

 

i am trying to compare the two values, but it doesnt seem to work.

the values:  $num1 = 1  and $array1[0] = 1.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.