Jump to content

[SOLVED] php randomly changing variable values.... any idea why?


Cabal

Recommended Posts

Any idea whats going on here?

 

I have a function which outputs an image to a filename which is specified by a combination of a variable inputted into the function, and a hard-coded location. The variable is being inputted to the function correctly - i placed an echo command the line before the function is called and that value is correct..... however an echo command within the function seems to show a different value. It is this changed value which is being used as the location, not the correct one which is being sent to the function

 

8081_B12345_53444900_10 becomes 8081_B12345_53444900_14

8081_B12345_53444900_U99 becomes 8081_B12345_53444900_V03

8081_B12345_53444900_aa becomes 8081_B12345_53444900_ae

 

Any idea what is causing this? It shouldn't be my coding as between the two echo commands all that happens is the value is passed to the function.

Link to comment
Share on other sites

in the funciton, the value is reinterpreted, transfered.

 

think about it:

 

$d = 1;
function  der($e);
{
}
der($d);

it transfers the data, and can easily change. and if you use DATE in that function anywhere to predict it... it will get the date AGAIN at the function start.

 

the important question is... what do you ahve to choose your last value?  ??_??_??_xx

what do you ahve determining that last section after the underscore?

Link to comment
Share on other sites

The value passed to the function is taken from an array value. The last bit of the file name corresponds to the file name without extension of a text file that was uploaded... this function translates the data within that file into an image. The whole of that value (the other bits... plus the file name without extension) are all put into an array. This is then looped and passed to the function.

 

The values have different names and dont reference each other except being passed into a function.

 

The start of the function is as follows

 

function biodraw($values, $maxx, $maxy, $points, $bimt)

{

//this echo doesn't show the correct value - shows the incorrect value

 

echo "$bimt<br>";

 

<SNIPPED.... AS IRRELEVANT UNDER HERE>

 

 

 

The section of code that passes the value to the function is as follows

 

//get the original file name from the array of file name

$thisfilename = substr(strrchr($okfilearray[$oki], '/'), 1);

$thisfilename = substr($thisfilename, 0, strrpos($thisfilename, 46));

 

//take the values from the output of a function (this part doesnt reference the file name at all)

//this is simply the output from the function which reads the relevant data from the file

$valdrawarray = $thisresult[4];

 

//declare variables

$maxx = "1";

$maxy = "1";

$points = "0";

$imt = $thisfilename;

 

//this bit shows the correct value

echo "$imt<br>";

 

if(is_array($valdrawarray))

{

foreach($valdrawarray as $thisvaldraw)

{

if($thisvaldraw[0] > $maxx)

{

$maxx = $thisvaldraw[0];

}

 

if($thisvaldraw[1] > $maxy)

{

$maxy = $thisvaldraw[1];

}

 

$points++;

$imt++;

}

 

biodraw($valdrawarray, $maxx, $maxy, $points, $imt);

}

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.