Jump to content

Variables not holding correct info ??


mherr170

Recommended Posts

Hello Everyone,

 

THanks to all who helped contribute to my last post!  I have returned for another question, this time regarding variables not seemingly holding the correct info.

 

A little background:  I have a text file with the rise and set times for the sun for everyday in the year 08.  I am reading it in, and setting the rise and set times for a Day object, which is contained in array in a Month object.  WHen reading in the information, i perform set methods to enter the data, and then I immediately use the get methods to print out the values I just set.  While reading in, they are the same.  Even the variable that is getting the information is printing out with the correct value.  For Example..

 

$first = strtok($t," ");
               for($i = 0; $i < strlen($t); $i++)
               {

                  $second = strtok(" ");

                //  echo "s= ";  
                //  echo $second; <-- HOLDS CORRECT DATA HERE
                //  echo " ";


                  //If second is null, it is the end of the line and break.
                  if($second == false)
                  {
                       break;
                  }

                  //Sets the sunrise time
                        $monthVect[$month]->dayVect[$day]->setRise($second);

                  //echo "getRise= ";
                  //echo $monthVect[$month]->dayVect[$day]->getRise(); <-- RETURNS CORRECT DATA
                  //Move onto the next token
//                  $second = strtok(" ");
                  $third = strtok(" ");
                  //echo "third equals ";
                  //echo $third; <-- AGAIN holds correct data
                  //echo " ";


                  //Again, if null, end of line and break.
                  //if($second == false)
                  if($third == false)
                  {
                       break;
                  }

                  //Sets the sunset time.
                  $monthVect[$month]->dayVect[$day]->setSet($third);

                  //echo "getSet= ";

                  //echo $monthVect[$month]->dayVect[$day]->getSet(); <-- and returns correct data


                  $month++;
               }//end of for loop


               $day++;

            }// end of <= 38 IF

 

However, further down my file when I am trying to out put the information based on any given day a user picks, no matter what I try to do, the getRise and getSet functions seem to be returning the same value!

 

$conVert = $monthVect[$monthIndex]->dayVect[$dayIndex-2]->getRise();

            $conVert2 = $monthVect[$monthIndex]->dayVect[$dayIndex-2]->getSet();

            //echo "conVert="; 
            //echo $conVert; <-- ALREADY HOLDS WRONG DATA!
                                     // <-- Even though this variable is returning from the getRise function, it already holds the value of the getSet function.

            //echo $monthVect[$monthIndex]->dayVect[$dayIndex-2]->getRise();
            //echo $monthVect[$monthIndex]->dayVect[$dayIndex-2]->getSet();
//And here, the above will print the same number twice, the set time.

 

 

Can anyone possibly understand why this is?  I have been looking over this for days and, to me, the code just isn't making sense.  However I'm sure there is something small I've missed.

 

Can anyone see anything I could be doing wrong?

 

THanks!

 

-Mike

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.