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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.