Jump to content

Storing values in Session Variable and doing simple calculations.


theITvideos

Recommended Posts

Hi there,

 

I am working on a PHP web form and I have a very simple situation I guess, I have a variable named: $MyVal

 

When I do

 

print_r($MyVal);

To see whats inside, I get:

 

SimpleXMLElement Object ( [0] => 8.23 )

Now I am assigning this variable into a session variable so that I can do calculations with it.

 

So I assign:

 

$_SESSION['MySesVal'] = $MyVal;

But after assigning to session variable, when I do my calculations:

 

$finalValue = $_SESSION['MySesVal'] * 4;

 

I get 0. So is it because the actual $MyVal variable has some XML stuff as:

 

SimpleXMLElement Object ( [0] => 8.23 )

 

So what is the right way to properly assign $MyVal variable to a session variable to do calculations.

 

Please reply.

 

All comments and feedbacks are always welcome. :)

 

Thank you!

 

There is no way to store simple xmlobject in session.

you can convert that object to array serialize it and save it in session and every time you want to do the calculation unserialize it and perform the operation on array.

 

to convert simple XML object to array there is good function on PHP.NET

http://www.php.net/manual/en/book.simplexml.php#98077

 

NOTE :- SimpleXMLElement wraps a libxml resource type. Resources cannot be serialized. On the next invocation, the resource representing the libxml Node object doesn't exist, so unserialization fails.

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.