A different array question

A different array question

am 20.08.2007 15:52:27 von Captain Nemo

I've been writing code lately that loops through the $_POST and
$_SESSION arrays and needs to determine if a particular member is a
scalar or an array.

I've found a test that works:

while (list($key, $value) = each($_POST))
{
if ((string) $value == "Array")
etc.

but it really looks a bit tacky to me.

Can anyone suggest something a bit more respectable?

Thanks.

Re: A different array question

am 20.08.2007 16:01:11 von Steve

is_array($value)


"Captain Nemo" wrote in message
news:v0hyi.9825$cw7.7926@text.news.blueyonder.co.uk...
| I've been writing code lately that loops through the $_POST and
| $_SESSION arrays and needs to determine if a particular member is a
| scalar or an array.
|
| I've found a test that works:
|
| while (list($key, $value) = each($_POST))
| {
| if ((string) $value == "Array")
| etc.
|
| but it really looks a bit tacky to me.
|
| Can anyone suggest something a bit more respectable?
|
| Thanks.
|
|
|

Re: A different array question

am 20.08.2007 16:26:12 von Robin Goodall

> "Captain Nemo" wrote in message
> news:v0hyi.9825$cw7.7926@text.news.blueyonder.co.uk...
> | I've been writing code lately that loops through the $_POST and
> | $_SESSION arrays and needs to determine if a particular member is a
> | scalar or an array.
> |
> | I've found a test that works:
> |
> | while (list($key, $value) = each($_POST))
> | {
> | if ((string) $value == "Array")
> | etc.
> |
> | but it really looks a bit tacky to me.
> |
> | Can anyone suggest something a bit more respectable?
> |
> | Thanks.
> |
Steve wrote:
> is_array($value)
>

Also, instead of that while statement why not use the cleaner (looking
at least):

foreach ($_POST as $key=>$value)


Robin

Re: A different array question

am 20.08.2007 16:47:44 von Captain Nemo

"Steve" wrote in message
news:q8hyi.3$bu5.2@newsfe03.lga...

> is_array($value)

Ahh... Thanks! I think I'm beginning to understand...

Re: A different array question

am 20.08.2007 16:47:44 von Captain Nemo

> Also, instead of that while statement why not use the cleaner
(looking
> at least):
>
> foreach ($_POST as $key=>$value)

Because I started PHP towards the end of PHP 3 and I've never got to
grips with the foreach() construct. Is it as easy as it looks? Do
you have to reset() the array afterwards like you do with each()?

Re: A different array question

am 20.08.2007 16:54:34 von luiheidsgoeroe

On Mon, 20 Aug 2007 16:47:44 +0200, Captain Nemo =

wrote:

>> Also, instead of that while statement why not use the cleaner
> (looking
>> at least):
>>
>> foreach ($_POST as $key=3D>$value)
>
> Because I started PHP towards the end of PHP 3 and I've never got to
> grips with the foreach() construct. Is it as easy as it looks? Do
> you have to reset() the array afterwards like you do with each()?

Yup, it's that easy, no setting to beginning or resetting afterwards =

needed.
-- =

Rik Wasmus