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
https://forums.phpfreaks.com/topic/92754-variables-not-holding-correct-info/
Share on other sites

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.