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!

 

Link to comment
Share on other sites

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.

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.