473,756 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

copying a multidimensiona l array to $_SESSION

Probably a simple question but I can't find the answer anyway.

Specifically, is it possible to copy a multidimensiona l array into the
$_SESSION array - ie a deep clone of all keys and data?

I naively assumed that

$_SESSION["myArray"'] = $myArray ;

would work but it doesn't appear to work. Is there a single function
or assignment I can use, or would I need to use a "foreach" at every
level?
---
Rob Tweed
M/Gateway Developments Ltd

Global DOMination with eXtc : http://www.mgateway.tzo.com
---
Jul 17 '05 #1
5 10918
Rob Tweed <rt****@blueyon der.co.uk> wrote in message news:<k2******* *************** **********@4ax. com>...
Probably a simple question but I can't find the answer anyway.

Specifically, is it possible to copy a multidimensiona l array into the
$_SESSION array - ie a deep clone of all keys and data?
Global DOMination with eXtc : http://www.mgateway.tzo.com


Example:
$_SESSION['string1'] = 'String1';
$_SESSION['string2'] = 'String2';
$_SESSION['array1'] = array(1,2,3,4,5 );
$_SESSION['array2'] = array(11,12,13, 14,15);
print_r($_SESSI ON);

---
"One who mix sports and patriotism is a barbarian"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2
Thanks Rajesh, but not quite what I wanted. Let me perhaps explain
what I need more fully:

Lets say I have a multidimensiona l array inside my PHP page, eg:

$myMDArray[$x]
$myMDArray[$x][$y]
$myMDArray[$x][$y][$z]

where $x, $y and $z may be many different values, and, as shown, there
may be data at various levels in the dimensional hierarchy.

How can I dump this complete array into $_SESSION, and then do the
reverse to recover it again in a later page?

Specifically, do I have to do it laboriously with "foreach" loops
through each level in $myMDArray, or can I use some simple merge
function or operator?

Rob
On 20 Nov 2003 06:31:36 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) wrote:
Rob Tweed <rt****@blueyon der.co.uk> wrote in message news:<k2******* *************** **********@4ax. com>...
Probably a simple question but I can't find the answer anyway.

Specifically, is it possible to copy a multidimensiona l array into the
$_SESSION array - ie a deep clone of all keys and data?
Global DOMination with eXtc : http://www.mgateway.tzo.com


Example:
$_SESSION['string1'] = 'String1';
$_SESSION['string2'] = 'String2';
$_SESSION['array1'] = array(1,2,3,4,5 );
$_SESSION['array2'] = array(11,12,13, 14,15);
print_r($_SESS ION);

---
"One who mix sports and patriotism is a barbarian"
Email: rrjanbiah-at-Y!com


---
Rob Tweed
M/Gateway Developments Ltd

Global DOMination with eXtc : http://www.mgateway.tzo.com
---
Jul 17 '05 #3

On 20-Nov-2003, Rob Tweed <rt****@blueyon der.co.uk> wrote:

On 20 Nov 2003 06:31:36 -0800, ng**********@re diffmail.com (R. Rajesh
Jeba Anbiah) wrote:
Rob Tweed <rt****@blueyon der.co.uk> wrote in message
news:<k2****** *************** ***********@4ax .com>...
Probably a simple question but I can't find the answer anyway.

Specifically, is it possible to copy a multidimensiona l array into the
$_SESSION array - ie a deep clone of all keys and data?
Global DOMination with eXtc : http://www.mgateway.tzo.com


Example:
$_SESSION['string1'] = 'String1';
$_SESSION['string2'] = 'String2';
$_SESSION['array1'] = array(1,2,3,4,5 );
$_SESSION['array2'] = array(11,12,13, 14,15);
print_r($_SESS ION);

---

Lets say I have a multidimensiona l array inside my PHP page, eg:

$myMDArray[$x]
$myMDArray[$x][$y]
$myMDArray[$x][$y][$z]

where $x, $y and $z may be many different values, and, as shown, there
may be data at various levels in the dimensional hierarchy.

How can I dump this complete array into $_SESSION, and then do the
reverse to recover it again in a later page?

Specifically, do I have to do it laboriously with "foreach" loops
through each level in $myMDArray, or can I use some simple merge
function or operator?


I don't see why you can't just say $_SESSION['myMDArray'] = $myMDArray;
However, if it really doesn't work you can always serialize()/unserialize()
the array before/after putting it in the $_SESSION superglobal.

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@wil lglen.net (it's reserved for spammers)
Jul 17 '05 #4
Rob Tweed <rt****@blueyon der.co.uk> schrieb:
Specifically, is it possible to copy a multidimensiona l array into the
$_SESSION array - ie a deep clone of all keys and data?
Yes.
I naively assumed that

$_SESSION["myArray"'] = $myArray ;

would work but it doesn't appear to work.


Your code is
$_SESSION['myArray'] = $myArray ;
I assume.

That should work and it works for me. There might be problems with this,
if register_global s is _on_. If register_global s is activated, then
change the name of the array index or the name of the variable:

$_SESSION['xmyArray'] = $myArray ;
or
$_SESSION['myArray'] = $xmyArray ;

Regards,
Matthias
Jul 17 '05 #5
The one thing I didn't see in your code sample was a call to
session_start() before any of the references to $_SESSION. This
should really be the first line in your application and might be your
problem.

Wes
> Specifically, is it possible to copy a multidimensiona l array into the
> $_SESSION array - ie a deep clone of all keys and data?
> Global DOMination with eXtc : http://www.mgateway.tzo.com

Example:
$_SESSION['string1'] = 'String1';
$_SESSION['string2'] = 'String2';
$_SESSION['array1'] = array(1,2,3,4,5 );
$_SESSION['array2'] = array(11,12,13, 14,15);
print_r($_SESS ION);

---

Lets say I have a multidimensiona l array inside my PHP page, eg:

$myMDArray[$x]
$myMDArray[$x][$y]
$myMDArray[$x][$y][$z]

where $x, $y and $z may be many different values, and, as shown, there
may be data at various levels in the dimensional hierarchy.

How can I dump this complete array into $_SESSION, and then do the
reverse to recover it again in a later page?

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
13840
by: Robert | last post by:
Im a beginner in PHP and Im having a problem with this code. Im trying to remove duplicate elements from an array created via $_GET. I want users to be able to click on a link which sends an email address to an array. I just want to remove duplicate email addresses from the array. Ive tried array_unique() on my test server but it doesnt work. So i tried to remove duplicates myself before storing them into the array. The script works...
2
16284
by: Håvard Olerud Eriksen | last post by:
I've been working on a webshop, and I've got most of the functionality up and running. One problem, however, that I don't seem to be able to solve is as follows. My shopping cart is stored in $_SESSION array. As I need to keep tabs on what items are ordered and their quantity I add elements like this: array_push($_SESSION,array($item => $quantity)); If I add three elements and then var_dump the global variable it spits out: array(3) { =>...
3
4712
by: Michelle | last post by:
Hi all, I am trying to store data in a $_SESSION variable (an array), but it reverts to empty every time my page is refreshed (due to a submit button click). I read the answer to the post "$_SESSION comes empty on next page" dated 2/4, whaich seems to be my problem. But the suggestions do not help me at all <see 1 & 2 below> 1-have you set session.save_path ?
4
1806
by: iannorton | last post by:
Hi, I've spent most of today trying to solve this problem, but sadly no luck. I have an shopping basket based on an array which stores the name, product id, quantity and price for products, i want to take the Information in the array and output the Quantity and Product ID information into variables so that i can pass them into a Select Statement and submit the order to the database.
1
8275
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a RankException. But the MSDN documentation says: When copying between multidimensional arrays, the array
5
3290
by: Victor Bazarov | last post by:
Below you will find some code I wrote to see if I could wrap array copying (especially for multi-dimensional arrays) in a simple class and/or function. It seems to work fine for one-dimensioned arrays as well as two-dimensioned ones. I am sure three- or more-dimensioned array are just as OK here. My concern was that I couldn't use 'std::copy' to copy multi-dimensional arrays. Perhaps in the future we'll see specialisations of...
26
6294
by: drako | last post by:
Hi, I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set of values to them based on data submitted from POST Fields. Code below: $_SESSION = array();
1
2565
by: Jankie | last post by:
I was reading one of the past thread supported by Pbmods.And as always contributing with excellence,he recommended this code for session management foreach($_POST as $key => $val) $_SESSION = $val; This translates all POST variables into the Session one.
9
4501
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize function: x = new int;
0
9431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9255
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9689
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6514
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.