Jump to content

simpleXML, Var's containing references, not values?


mmccracken

Recommended Posts

Hi All,

-Background:

 

Creating a game in flash, where if the player gets enough points, enters into the highscore, which is stored in an xml file.

Below is the snippet where my php problem/lack of knowledge is, while the attached file contains the php file that reads the xml content, checks where in the xml score list the new entry should go, and then pushes everything down one level and disregards the last entry as there's a new entry, to keep the full amount of entries to 20.

 

Problem:

 

The variables that holds the old values for where the new position goes, changes without me changing it.

Is the variable just pointing to where it's created from. How do I solidly make it "it's own" and not a reference? If not is correct, what am I doing wrong/missunderstanding?

 

$oldTempName = $myXml->score[$newScorePosition - 1]->meta[0];

$oldTempScore = $myXml->score[$newScorePosition - 1]->points;

// this returns the original value:

echo "missing should be here : " . $oldTempName . " and " . $oldTempScore . "<br />";

$myXml->score[$newScorePosition - 1]->meta[0] = $fakeName;

$myXml->score[$newScorePosition - 1]->points = $fakeScore;

// this returns the $fakeName & $fakeScore, not the original value:

echo "missing should be here : " . $oldTempName . " and " . $oldTempScore . "<br />";

 

attaching full php script + xml file as a .txt file.

 

 

[attachment deleted by admin]

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.