473,385 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

A different array question

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.

Aug 20 '07 #1
5 1178
is_array($value)
"Captain Nemo" <re*****************@yahooSPAM.comwrote in message
news:v0*****************@text.news.blueyonder.co.u k...
| 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.
|
|
|
Aug 20 '07 #2
"Captain Nemo" <re*****************@yahooSPAM.comwrote in message
news:v0*****************@text.news.blueyonder.co.u k...
| 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
Aug 20 '07 #3
"Steve" <no****@example.comwrote in message
news:q8***********@newsfe03.lga...
is_array($value)
Ahh... Thanks! I think I'm beginning to understand...
Aug 20 '07 #4
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()?
Aug 20 '07 #5
Rik
On Mon, 20 Aug 2007 16:47:44 +0200, Captain Nemo
<re*****************@yahooSPAM.comwrote:
>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()?
Yup, it's that easy, no setting to beginning or resetting afterwards
needed.
--
Rik Wasmus
Aug 20 '07 #6

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

Similar topics

1
by: houstoncity | last post by:
Could someone help me with the following problem? I am running the pages on a php server. On page 1, I ask users to answer one radio-button question which has options (a), (b), (c), and (d). ...
4
by: John MacIntyre | last post by:
Hi, I have a page with a series of child pages loaded into an iframe. When I move from page to page, I store an object containing the child's control data in a variable on the main page, then...
16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
7
by: Ron | last post by:
Hello, I have 4 classes that use 4 DTS packages on 4 different tables. So I have Dim cls1 As New clsDTS1, cls2 As New clsDTS2 Dim cls3 As New clsDTS3, cls4 As New clsDTS4 Each class has a...
13
by: ANSHUL | last post by:
PLEASE PROVIDE ME D SOLUTION CODE FOR DIS PROBLEM. SELECTION SORT IS BASED ON D FOLLOWING IDEA: SELECTING D LARGEST ARRAY ELEMENT AND SWAPPING IT WITH THE LAST ARRAY ELEMENT LEAVES AN UNSORTED...
9
by: joshc | last post by:
Hi, I have an array defined in one file with an intializer as follows: int arr = {0, 1, 2, 3}; I have a declaration of the array in another file as follows: extern int arr;
4
by: Ray | last post by:
Hello, While reading another guy's I found myself a bit confused by his way of declaring his class--I usually declare a class like this: function Foo() { this.blah = true; this.bleh = false;...
0
by: R | last post by:
Hi all, I have a simple question about locale and PHP5. I'm using polish characters but I encode them in UTF-8. I was sorting an array with usort($array, 'strcoll'); but I've entred a...
18
by: MajorSetback | last post by:
I am using the Redhat version of Linux and GNU C++. It is not clear to me whether this is a Linux issue or a C++ issue. I do not have this problem running the same program on Windows but...
5
by: whiskers | last post by:
Hello, gurus. I spent an hour looking for the answer to this and couldn't find one that pleased me (I don't want to use a base class, which seems to be a solution). So I have a function that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.