By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,313 Members | 1,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,313 IT Pros & Developers. It's quick & easy.

"Array to String Conversion" error when constructing a multi-dimensional array

P: n/a
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["increment"] = array();
$x = 0 // Counter - This will be
incremented

$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
It keeps throwing out that error, and does not write any of the POST
Values to the array (the POST values are definitely getting sent, so
that is not the problem).

If I dump out the value of $_SESSION["increment"], I get "1A" ?!?

I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?

Thanks
Neil.

Jan 17 '07 #1
Share this Question
Share on Google+
26 Replies


P: n/a
drako wrote:
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["increment"] = array();
$x = 0 // Counter - This will be
incremented

$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
It keeps throwing out that error, and does not write any of the POST
Values to the array (the POST values are definitely getting sent, so
that is not the problem).

If I dump out the value of $_SESSION["increment"], I get "1A" ?!?

I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?

Thanks
Neil.
Hi Neil,

Your code looks perfectly OK to me.
Are you 100% sure this is where the error is thrown?
Did you try:
<pre>
<?php print_r($_POST); ?>
</pre>

Does it produce all used postvars you expect?

Regards,
Erwin Moller
Jan 17 '07 #2

P: n/a
Erwin,

I have tried <?php print_r($_POST); ?>, and it outputs all the POST
vars that were submitted. So now problem here.

And the error is thrown at the line that begins
"$_SESSION["increment"][$x] ........"

I have tried this code on two different systems (5.1.6 on OSX, and
5.2.0 on NetBSD), and the same error keeps occuring.

Very puzzling.

Neil.
Erwin Moller wrote:
drako wrote:
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["increment"] = array();
$x = 0 // Counter - This will be
incremented

$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
It keeps throwing out that error, and does not write any of the POST
Values to the array (the POST values are definitely getting sent, so
that is not the problem).

If I dump out the value of $_SESSION["increment"], I get "1A" ?!?

I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?

Thanks
Neil.

Hi Neil,

Your code looks perfectly OK to me.
Are you 100% sure this is where the error is thrown?
Did you try:
<pre>
<?php print_r($_POST); ?>
</pre>

Does it produce all used postvars you expect?

Regards,
Erwin Moller
Jan 17 '07 #3

P: n/a
drako wrote:
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["increment"] = array();
Try doing <?php print_r($_SESSION["increment"]); ?here ... (*)
$x = 0 // Counter - This will be
incremented
(*) do you have any code in here?
What does <?php print_r($increment); ?tell you?

(*) ... and an other <?php print_r($_SESSION["increment"]); ?here.
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
Heiko
--
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/ Heiko Richler: Computer - Know How!
http://www.richler.info/ private Homepage
Jan 17 '07 #4

P: n/a
OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" =>
$_POST["increment_comm_date1"],
"increment_comm_date2" =>
$_POST["increment_comm_date2"],
"increment_comm_date3" =>
$_POST["increment_comm_date3"]);

echo '3: ';print_r($_SESSION["increment"]);exit;

<------->
The output is:

1: 1
2:
3: 1A
I'm still no wiser as to what is going on here....

Rgds
Neil.
Heiko Richler wrote:
drako wrote:
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["increment"] = array();

Try doing <?php print_r($_SESSION["increment"]); ?here ... (*)
$x = 0 // Counter - This will be
incremented

(*) do you have any code in here?
What does <?php print_r($increment); ?tell you?

(*) ... and an other <?php print_r($_SESSION["increment"]); ?here.
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);

Heiko
--
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/ Heiko Richler: Computer - Know How!
http://www.richler.info/ private Homepage
Jan 17 '07 #5

P: n/a
"drako" <ne**@invidion.co.ukwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';
I don't understand what this $increment variable has to do with anything.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Jan 18 '07 #6

P: n/a


Quote:
I don't understand what this $increment variable has to do with anything.
It doesn't actually relate to anything; but I suspect it was suggested
just to see if anything was output - and nothing was output.

I know if 'register_globals' is switched on, this could potentially
cause a problem, but in this case, globals is switched off, so is not
the problem.

I now suspect this is session-related in someway. As the code looks OK,
the problem arises from elsewhere....

Kimmo Laine wrote:
"drako" <ne**@invidion.co.ukwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';

I don't understand what this $increment variable has to do with anything.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Jan 18 '07 #7

P: n/a
Rik
drako wrote:
Don't fix bottom-posting, fix topposting.....
Kimmo Laine wrote:
>"drako" <ne**@invidion.co.ukwrote in message
news:11**********************@a75g2000cwd.googleg roups.com...
>>OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';

I don't understand what this $increment variable has to do with
anything.

It doesn't actually relate to anything; but I suspect it was
suggested just to see if anything was output - and nothing was output.

I know if 'register_globals' is switched on, this could potentially
cause a problem, but in this case, globals is switched off, so is not
the problem.

I now suspect this is session-related in someway. As the code looks
OK, the problem arises from elsewhere....
Nope.
Keep in mind, that on strings, the [] will get or set the character of the
string at that particular location. My suspicion is that you don't give us
the real code (for where would the incrementation take place?), and you
turn the array into the string ( or number) '1' somewhere. (This often
happens when you use the return of a function (true) that works be a
reference instead of a return by accident.)

So, in the first loop, we've made $_SESSION["increment"] into a string by
accident. On the second loop, if $x = 1, that's the second position in the
string (which was not previously set). You try to set a character to an
array, so the array is converted to a string ('Array'), then it takes the
first character ('A') from that string, and put it at position 1. Hence
resulting in '1A'.

If you gave us the real code, I'd bet we'd spot where the actual overriding
on $_SESSION["increment"] takes place.
--
Rik Wasmus
Jan 18 '07 #8

P: n/a
Rik wrote:
drako wrote:
Don't fix bottom-posting, fix topposting.....
>Kimmo Laine wrote:
>>"drako" <ne**@invidion.co.ukwrote in message
news:11**********************@a75g2000cwd.google groups.com...
OK,

I inserted the debugging statements as you suggested:
$_SESSION["increment"] = array();
echo '1: ';print_r($_SESSION["increment"]);echo '<br>';

$x = 0 // Counter - This will be
incremented
echo '2: ';print_r($increment); echo '<br>';

I don't understand what this $increment variable has to do with
anything.

It doesn't actually relate to anything; but I suspect it was
suggested just to see if anything was output - and nothing was output.

I know if 'register_globals' is switched on, this could potentially
cause a problem, but in this case, globals is switched off, so is not
the problem.

I now suspect this is session-related in someway. As the code looks
OK, the problem arises from elsewhere....

Nope.
Keep in mind, that on strings, the [] will get or set the character of the
string at that particular location. My suspicion is that you don't give us
the real code (for where would the incrementation take place?), and you
turn the array into the string ( or number) '1' somewhere. (This often
happens when you use the return of a function (true) that works be a
reference instead of a return by accident.)

So, in the first loop, we've made $_SESSION["increment"] into a string by
accident. On the second loop, if $x = 1, that's the second position in
the string (which was not previously set). You try to set a character to
an array, so the array is converted to a string ('Array'), then it takes
the
first character ('A') from that string, and put it at position 1. Hence
resulting in '1A'.

If you gave us the real code, I'd bet we'd spot where the actual
overriding on $_SESSION["increment"] takes place.
Damn Rik, sometimes you are scaringly smart.
That sounds like a very probable scenario you described and deducted from
the sparse information given.
Respect!

Erwin Moller
Jan 18 '07 #9

P: n/a
drako wrote:
I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?
There doesn't seem to be anything wrong with the code you posted (except
for a missing semicolon after $x = 0), so I suspect the problem lies
somewhere in your other code.

Because of this missing semicolon, I suspect you have chopped out a
section of code between '$x=0' and '$_SESSION["increment"][$x]=array(...)'.
That is almost certainly where your problem lies. In particular, I think
you may have assigned some non-integer value to $x at some point.

Do 'print_r($x);' just before the error happens and see what you see.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 18 '07 #10

P: n/a
You are correct in assuming that I chopped out a line when I posted
this...

The missing line between '$x=0' and
'$_SESSION["increment"][$x]=array(...)'.

is

if(isset($_SESSION["increments"])) {$x =
count($_SESSION["increments"]);}

The purpose is to count the number of entries in the array - if count
returns '5', then the last value of $x would have been 4, so we can
assign '5' as the next value in the array.

Could this be the offending line...

Toby Inkster wrote:
drako wrote:
I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.

Any suggestions or hints ?

There doesn't seem to be anything wrong with the code you posted (except
for a missing semicolon after $x = 0), so I suspect the problem lies
somewhere in your other code.

Because of this missing semicolon, I suspect you have chopped out a
section of code between '$x=0' and '$_SESSION["increment"][$x]=array(...)'.
That is almost certainly where your problem lies. In particular, I think
you may have assigned some non-integer value to $x at some point.

Do 'print_r($x);' just before the error happens and see what you see.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Jan 18 '07 #11

P: n/a

Sorry, the extra line of code above should have read:

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}

I just noticed the typo, in case anyone has been sharp enough to spot
it...
drako wrote:
You are correct in assuming that I chopped out a line when I posted
this...

The missing line between '$x=0' and
'$_SESSION["increment"][$x]=array(...)'.

is

if(isset($_SESSION["increments"])) {$x =
count($_SESSION["increments"]);}

The purpose is to count the number of entries in the array - if count
returns '5', then the last value of $x would have been 4, so we can
assign '5' as the next value in the array.

Could this be the offending line...

Toby Inkster wrote:
drako wrote:
I'm sure that there is a pretty simple mistake lurking somewhere - I
just can't seem to figure it out.
>
Any suggestions or hints ?
There doesn't seem to be anything wrong with the code you posted (except
for a missing semicolon after $x = 0), so I suspect the problem lies
somewhere in your other code.

Because of this missing semicolon, I suspect you have chopped out a
section of code between '$x=0' and '$_SESSION["increment"][$x]=array(...)'.
That is almost certainly where your problem lies. In particular, I think
you may have assigned some non-integer value to $x at some point.

Do 'print_r($x);' just before the error happens and see what you see.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Jan 18 '07 #12

P: n/a
drako wrote:
Sorry, the extra line of code above should have read:

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
Do you know you do not need $x?

See "Creating/modifying with square-bracket syntax" at
http://www.php.net/manual/en/language.types.array.php

Heiko
--
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/ Heiko Richler: Computer - Know How!
http://www.richler.info/ private Homepage
Jan 18 '07 #13

P: n/a
Rik
drako wrote:
drako wrote:
>You are correct in assuming that I chopped out a line when I posted
this...

The missing line between '$x=0' and
'$_SESSION["increment"][$x]=array(...)'.

is

if(isset($_SESSION["increments"])) {$x =
count($_SESSION["increments"]);}

The purpose is to count the number of entries in the array - if count
returns '5', then the last value of $x would have been 4, so we can
assign '5' as the next value in the array.

Could this be the offending line...
Sorry, the extra line of code above should have read:

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}

I just noticed the typo, in case anyone has been sharp enough to spot
it...
But that's not it afaik. See the comment about just using empty [], this
will just add an array-value to the end.

However, there's something else going on in the adding. Posting the total
code that works on $_SESSION["increment"] woudl speed up the process :-).

You probably have a $_SESSION["increment"] = something(); somehere, where
the function just returns true instead of a processed array, casting it to
the '1' string.
--
Rik Wasmus
Jan 18 '07 #14

P: n/a
Rik
Erwin Moller wrote:
Rik wrote:
>>I now suspect this is session-related in someway. As the code looks
OK, the problem arises from elsewhere....

Nope.
Keep in mind, that on strings, the [] will get or set the character
of the string at that particular location. My suspicion is that you
don't give us the real code (for where would the incrementation take
place?), and you turn the array into the string ( or number) '1'
somewhere. (This often happens when you use the return of a function
(true) that works be a reference instead of a return by accident.)

So, in the first loop, we've made $_SESSION["increment"] into a
string by accident. On the second loop, if $x = 1, that's the
second position in the string (which was not previously set). You
try to set a character to an array, so the array is converted to a
string ('Array'), then it takes the
first character ('A') from that string, and put it at position 1.
Hence resulting in '1A'.

If you gave us the real code, I'd bet we'd spot where the actual
overriding on $_SESSION["increment"] takes place.

Damn Rik, sometimes you are scaringly smart.
Well, that remains to be seen, but thank you, would be nice if I would get
paid that way though :-)
That sounds like a very probable scenario you described and deducted
from the sparse information given.
It helps that I cannot get the difference of array_walk() and array_map in
my head, so I'm used to seeing some '1''s or 'A's..

Now let's get the OP to post the code he uses in it's entirety to claim my
fame :-)
--
Rik Wasmus
Jan 18 '07 #15

P: n/a
OK,

Here is the code in its entireity:

[It is wrapped around an IF statement to process upon a certain
condition].

if($_POST['increment'] == 1) {

$x = 0;

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
}
Rik wrote:
Erwin Moller wrote:
Rik wrote:
>I now suspect this is session-related in someway. As the code looks
OK, the problem arises from elsewhere....

Nope.
Keep in mind, that on strings, the [] will get or set the character
of the string at that particular location. My suspicion is that you
don't give us the real code (for where would the incrementation take
place?), and you turn the array into the string ( or number) '1'
somewhere. (This often happens when you use the return of a function
(true) that works be a reference instead of a return by accident.)

So, in the first loop, we've made $_SESSION["increment"] into a
string by accident. On the second loop, if $x = 1, that's the
second position in the string (which was not previously set). You
try to set a character to an array, so the array is converted to a
string ('Array'), then it takes the
first character ('A') from that string, and put it at position 1.
Hence resulting in '1A'.

If you gave us the real code, I'd bet we'd spot where the actual
overriding on $_SESSION["increment"] takes place.
Damn Rik, sometimes you are scaringly smart.

Well, that remains to be seen, but thank you, would be nice if I would get
paid that way though :-)
That sounds like a very probable scenario you described and deducted
from the sparse information given.

It helps that I cannot get the difference of array_walk() and array_map in
my head, so I'm used to seeing some '1''s or 'A's..

Now let's get the OP to post the code he uses in it's entirety to claim my
fame :-)
--
Rik Wasmus
Jan 18 '07 #16

P: n/a
Rik
drako wrote:
OK,

Here is the code in its entireity:

[It is wrapped around an IF statement to process upon a certain
condition].

if($_POST['increment'] == 1) {

$x = 0;

if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
}
Is your $_SESSION['increment'] accessed/altered anywhere else in the
script? Check for it.
Also, add this before "if($_POST['increment'] == 1)":

if(isset($_SESSION['increment'])) var_dump($_SESSION['incremenet']);

Most likely, you overwrite the $_SESSION['increment'] somewhere else in
your code, so it get's cast to a string. Check your code for every
'$_SESSION['increment']= ', and carefully consider the return of the
function after it...
--
Rik Wasmus
Jan 19 '07 #17

P: n/a
On Jan 19, 5:15 am, "Rik" <luiheidsgoe...@hotmail.comwrote:
drako wrote:
OK,
Here is the code in its entireity:
[It is wrapped around an IF statement to process upon a certain
condition].
if($_POST['increment'] == 1) {
$x = 0;
if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
}Is your $_SESSION['increment'] accessed/altered anywhere else in the
script? Check for it.
Also, add this before "if($_POST['increment'] == 1)":

if(isset($_SESSION['increment'])) var_dump($_SESSION['incremenet']);

Most likely, you overwrite the $_SESSION['increment'] somewhere else in
your code, so it get's cast to a string. Check your code for every
'$_SESSION['increment']= ', and carefully consider the return of the
function after it...
--
Rik Wasmus
Concerning your earlier post, great deductive reasoning, Rik. *bows*

Just to reiterate to the OP, you need to check if you're assigning
$_SESSION['increment'] a function's return value, or possibly even
directly a string, at some other point (potentially in a different
file, since it is a session variable).

Also, you could a foreach loop, so as not to manually maintain the
array's index.
---
Curtis

Jan 20 '07 #18

P: n/a

I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort' in
order to process the array data.

Thanks for all your help and suggestions on this one.

Rgds
Neil.
Curtis wrote:
On Jan 19, 5:15 am, "Rik" <luiheidsgoe...@hotmail.comwrote:
drako wrote:
OK,
Here is the code in its entireity:
[It is wrapped around an IF statement to process upon a certain
condition].
if($_POST['increment'] == 1) {
$x = 0;
if(isset($_SESSION["increment"])) {$x =
count($_SESSION["increment"]);}
$_SESSION["increment"][$x] = array("increment_bond" =>
$_POST["increment_bond"],
"increment_amount" = $_POST["increment_amount"],
"increment_comm_date1" = $_POST["increment_comm_date1"],
"increment_comm_date2" =$_POST["increment_comm_date2"],
"increment_comm_date3" = $_POST["increment_comm_date3"]);
}Is your $_SESSION['increment'] accessed/altered anywhere else in the
script? Check for it.
Also, add this before "if($_POST['increment'] == 1)":

if(isset($_SESSION['increment'])) var_dump($_SESSION['incremenet']);

Most likely, you overwrite the $_SESSION['increment'] somewhere else in
your code, so it get's cast to a string. Check your code for every
'$_SESSION['increment']= ', and carefully consider the return of the
function after it...
--
Rik Wasmus

Concerning your earlier post, great deductive reasoning, Rik. *bows*

Just to reiterate to the OP, you need to check if you're assigning
$_SESSION['increment'] a function's return value, or possibly even
directly a string, at some other point (potentially in a different
file, since it is a session variable).

Also, you could a foreach loop, so as not to manually maintain the
array's index.
---
Curtis
Jan 22 '07 #19

P: n/a
Rik
drako wrote:
I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort' in
order to process the array data.
[despirately trying to claim the fame]

Well, you're copying the POST to the SESSION somewhere in your code in that
case, as it is not a PHP feature. This works fine:
<?php
session_start();
if(!isset($_POST['submit'])){
$_SESSION['increment'] = 'This is the session value';
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="increment">
<input type="submit" name="submit">
</form>
<pre>
<?php
echo "The SESSION is {$_SESSION['increment']}\n";
echo "The POST is {$_POST['increment']}\n";
?>
</pre>

And upon posting "This is the post value" in correctly displays:
The SESSION is This is the session value
The POST is This is the post value

I'd say my claim you've turned it into a string stands :-)

[/end of sad little claim here]
--
Rik Wasmus
Jan 22 '07 #20

P: n/a
Rik wrote:
drako wrote:
>I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort' in
order to process the array data.

[despirately trying to claim the fame]

Well, you're copying the POST to the SESSION somewhere in your code in that
case, as it is not a PHP feature. This works fine:
<?php
session_start();
if(!isset($_POST['submit'])){
$_SESSION['increment'] = 'This is the session value';
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="increment">
<input type="submit" name="submit">
</form>
<pre>
<?php
echo "The SESSION is {$_SESSION['increment']}\n";
echo "The POST is {$_POST['increment']}\n";
?>
</pre>

And upon posting "This is the post value" in correctly displays:
The SESSION is This is the session value
The POST is This is the post value

I'd say my claim you've turned it into a string stands :-)

[/end of sad little claim here]
Or, maybe register_globals is enabled?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 23 '07 #21

P: n/a
Rik
Jerry Stuckle wrote:
Rik wrote:
>drako wrote:
>>I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort'
in order to process the array data.

Well, you're copying the POST to the SESSION somewhere in your code
in that case, as it is not a PHP feature. This works fine:

Or, maybe register_globals is enabled?
That would not overwrite the $_POST & $_SESSION arrays, and even then, the
$_SESSION would win the $increment, and the $_POST value would be
discarded.
--
Rik Wasmus
Jan 23 '07 #22

P: n/a
Rik wrote:
Jerry Stuckle wrote:
>Rik wrote:
>>drako wrote:
I got this working in the end. It seemed that having the following
variables caused some clash:

$_POST['increment']
$_SESSION['increment']

once I changed this to $_SESSION['increments'] (notice the plural),
then it was creating arrays within the session variable as expected,
and I can now run it through a 'foreach' loop and 'array_multisort'
in order to process the array data.
Well, you're copying the POST to the SESSION somewhere in your code
in that case, as it is not a PHP feature. This works fine:
Or, maybe register_globals is enabled?

That would not overwrite the $_POST & $_SESSION arrays, and even then, the
$_SESSION would win the $increment, and the $_POST value would be
discarded.
As posted, that is true. But we don't know what other code he has
which isn't posted. Perhaps he has something like $increment=4; in
another place in his program.

Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 23 '07 #23

P: n/a
On Jan 23, 4:20 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.
Indeed, but it seems quite rare that change would be made to the
default order. Also, the OP stated above, he has register_globals off.

--
Curtis

Jan 24 '07 #24

P: n/a
Rik
Jerry Stuckle wrote:
Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.
Ah, this is a setting? I memorized GPCS, it never occured to me this was
configurable. Learn something new every day :-)

--
Rik Wasmus
Jan 24 '07 #25

P: n/a
Curtis wrote:
On Jan 23, 4:20 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.

Indeed, but it seems quite rare that change would be made to the
default order. Also, the OP stated above, he has register_globals off.

--
Curtis
Curtis,

Yes, it's unusual, but not unheard of.

As for register_globals being off. I've had people claim that is the
case - but then later found out it wasn't. They were looking at the
wrong php.ini file and/or had it overridden. I never trust any settings
without seeing what phpinfo() has to say.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 24 '07 #26

P: n/a
On Jan 24, 9:06 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Curtis wrote:
On Jan 23, 4:20 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Also, which variable wins the $increment depends on the php.ini
settings. The default is GPCS (Get/Post/Cookie/Session), but that can
be changed.
Indeed, but it seems quite rare that change would be made to the
default order. Also, the OP stated above, he has register_globals off.
--
CurtisCurtis,

Yes, it's unusual, but not unheard of.

As for register_globals being off. I've had people claim that is the
case - but then later found out it wasn't. They were looking at the
wrong php.ini file and/or had it overridden. I never trust any settings
without seeing what phpinfo() has to say.
That's a good point, Jerry. Ruling things out too early can impede
problem-solving. When I was developing one project, I didn't realize my
host had register_globals on, ugh, quite a pain, if only I had been
wise enough to check phpinfo() before hand. Now I know better, at
least.

--
Curtis

Jan 25 '07 #27

This discussion thread is closed

Replies have been disabled for this discussion.