It will be in memory.
How would this be converted to JSON so it can be sent back to the client?
Main Topics
Browse All TopicsDear Experts,
If I wanted to append some sort of string or array structure in PHP, what is the best way to do that?
Lets say I have some data stored on some sort of variable on the server, how do I add to that variable with values received from the client?
Basically, I want to send the client cart data in JSON format, but I do not know how to add to the cart on the server when new items are selected on the clientside page.
Please help
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Are you aware that PHP supports JSON (natively after 5.2)
http://www.php.net/manual/
Also, to communicate with the server, there is an AJAX example at Wikipedia that may help
http://en.wikipedia.org/wi
OK - I'm still not understanding this. If you are sending stuff from the server to the client, why not simply out the data directly as javascript? Something like so
<?php
.... code
foreach ($arrayValue as $aKey => $aValue )
$values .= ..... some processing to lay the values out as a javascript string
echo "<script type='text/javascipt'>";
echo " var jsArray = array( $values ); ";
echo "</script>";
?>
That way the javascript has the PHP values in the code. If you really must have JSON code then you can surely do the same thing using PHP's JSON encode function (see earlier post) and then output that directly into the HTML javascript with the relevant JSON handler in the javascript. Since you say you wil not be using AJAX then unless you intend to use JSON-RPC ( http://jsonrpcphp.org ) or something like it then surely outputting the data directly into the HTML is the easiest way?
I can't help feeling I'm missing something here......
"The data the server gets, should be added to the structure on the server."
I do not know what you mean by this
Business Accounts
Answer for Membership
by: elvin66Posted on 2009-10-30 at 03:11:23ID: 25701502
What exactly is in the stored string on the server? Is it stored in a database or just in memory? If it is just a matter of adding new data to an already defined variable then just do
$stored_data = $stored_data.$new_data;
or $stored_data = ($stored_data + $new_data); // assuming it is a numerical value