Ask a Question related to PHP Development, Design and Development.
-
Rob Tweed #1
copying a multidimensional array to $_SESSION
Probably a simple question but I can't find the answer anyway.
Specifically, is it possible to copy a multidimensional 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 : [url]http://www.mgateway.tzo.com[/url]
---
Rob Tweed Guest
-
multidimensional array assignment
dear all, I am a facing a problem in multidimensional array. The problem is that when i am trying to copy the value of arry named 'str' to... -
creating a multidimensional array
How can I combine two arrays in cfscript to form one multidimensional array? For example, I have two arrays: firstarray=fred; firstarray=jim;... -
Multidimensional array: see if 1st key is available
Hi, I've got an multidimensional array $ret = $country_code; Now I want to see if $countryCode is even in that array, because if it's not, it... -
copying a multidimensional array
Hi: whatz the best way to copy an multidimensional array onto another. I have never used something like clone, just want to know whatz the easiest... -
Split multidimensional array into 4 multidimensional arrays
Hello everyone, I have a multidimensional array that I need to split into 4 multidimensional arrays. I've tried the examples from the... -
R. Rajesh Jeba Anbiah #2
Re: copying a multidimensional array to $_SESSION
Rob Tweed <rtweed@blueyonder.co.uk> wrote in message news:<k2aprv8jmmggldr6ofu1qpid77v1cp81lj@4ax.com>. ..
Example:> Probably a simple question but I can't find the answer anyway.
>
> Specifically, is it possible to copy a multidimensional array into the
> $_SESSION array - ie a deep clone of all keys and data?
> Global DOMination with eXtc : [url]http://www.mgateway.tzo.com[/url]
$_SESSION['string1'] = 'String1';
$_SESSION['string2'] = 'String2';
$_SESSION['array1'] = array(1,2,3,4,5);
$_SESSION['array2'] = array(11,12,13,14,15);
print_r($_SESSION);
---
"One who mix sports and patriotism is a barbarian"
Email: rrjanbiah-at-Y!com
R. Rajesh Jeba Anbiah Guest
-
Rob Tweed #3
Re: copying a multidimensional array to $_SESSION
Thanks Rajesh, but not quite what I wanted. Let me perhaps explain
what I need more fully:
Lets say I have a multidimensional 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, [email]ng4rrjanbiah@rediffmail.com[/email] (R. Rajesh
Jeba Anbiah) wrote:
--->Rob Tweed <rtweed@blueyonder.co.uk> wrote in message news:<k2aprv8jmmggldr6ofu1qpid77v1cp81lj@4ax.com>. ..>>> Probably a simple question but I can't find the answer anyway.
>>
>> Specifically, is it possible to copy a multidimensional array into the
>> $_SESSION array - ie a deep clone of all keys and data?
>> Global DOMination with eXtc : [url]http://www.mgateway.tzo.com[/url]
> 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($_SESSION);
>
>---
> "One who mix sports and patriotism is a barbarian"
>Email: rrjanbiah-at-Y!com
Rob Tweed
M/Gateway Developments Ltd
Global DOMination with eXtc : [url]http://www.mgateway.tzo.com[/url]
---
Rob Tweed Guest
-
Tom Thackrey #4
Re: copying a multidimensional array to $_SESSION
On 20-Nov-2003, Rob Tweed <rtweed@blueyonder.co.uk> wrote:
I don't see why you can't just say $_SESSION['myMDArray'] = $myMDArray;>
> On 20 Nov 2003 06:31:36 -0800, [email]ng4rrjanbiah@rediffmail.com[/email] (R. Rajesh
> Jeba Anbiah) wrote:
>> Lets say I have a multidimensional array inside my PHP page, eg:> >Rob Tweed <rtweed@blueyonder.co.uk> wrote in message
> >news:<k2aprv8jmmggldr6ofu1qpid77v1cp81lj@4ax.com> ...> >> >> Probably a simple question but I can't find the answer anyway.
> >>
> >> Specifically, is it possible to copy a multidimensional array into the
> >> $_SESSION array - ie a deep clone of all keys and data?
> >> Global DOMination with eXtc : [url]http://www.mgateway.tzo.com[/url]
> > 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($_SESSION);
> >
> >---
>
> $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?
>
However, if it really doesn't work you can always serialize()/unserialize()
the array before/after putting it in the $_SESSION superglobal.
--
Tom Thackrey
[url]www.creative-light.com[/url]
tom (at) creative (dash) light (dot) com
do NOT send email to [email]jamesbutler@willglen.net[/email] (it's reserved for spammers)
Tom Thackrey Guest
-
Matthias Esken #5
Re: copying a multidimensional array to $_SESSION
Rob Tweed <rtweed@blueyonder.co.uk> schrieb:
Yes.> Specifically, is it possible to copy a multidimensional array into the
> $_SESSION array - ie a deep clone of all keys and data?
Your code is> I naively assumed that
>
> $_SESSION["myArray"'] = $myArray ;
>
> would work but it doesn't appear to work.
$_SESSION['myArray'] = $myArray ;
I assume.
That should work and it works for me. There might be problems with this,
if register_globals is _on_. If register_globals 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
Matthias Esken Guest
-
Wes Bailey #6
Re: copying a multidimensional array to $_SESSION
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
> > Lets say I have a multidimensional array inside my PHP page, eg:> > >> Specifically, is it possible to copy a multidimensional array into the
> > >> $_SESSION array - ie a deep clone of all keys and data?
> > >> Global DOMination with eXtc : [url]http://www.mgateway.tzo.com[/url]
> > >
> > > 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($_SESSION);
> > >
> > >---
> >
> > $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?
> >Wes Bailey Guest



Reply With Quote

