473,395 Members | 1,456 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,395 software developers and data experts.

explicit numeric keys vs item position

Hi

Say if I have a mixed array:

$array = array("item1", "2"=>"item2", "5", "item4key"=>"item4")

Is it possible while looping through the array (foreach ($array as
$key=>$val)) to check if an item has an explicit key specified instead
of its automatically assigned position key?

Apr 27 '06 #1
2 1344
Rik
ni******@hotmail.com wrote:
Hi

Say if I have a mixed array:

$array = array("item1", "2"=>"item2", "5", "item4key"=>"item4")

Is it possible while looping through the array (foreach ($array as
$key=>$val)) to check if an item has an explicit key specified instead
of its automatically assigned position key?


It seems like the explicit keys aren't numbers, in that case this will do:

$explicit = (is_numeric($key)) ? false : true;

If your explicit keys can be numbers I don't think it's possible, to my
knowledge PHP doesn''t store information about how an elemtn is added in an
array.

Grtz,

--
Rik Wasmus
Apr 27 '06 #2
ni******@hotmail.com wrote:
Hi

Say if I have a mixed array:

$array = array("item1", "2"=>"item2", "5", "item4key"=>"item4")

Is it possible while looping through the array (foreach ($array as
$key=>$val)) to check if an item has an explicit key specified instead
of its automatically assigned position key?


Confused am I. An explicit key? An automatically assigned position key? If a
key is not explicitly used in the assignment, then the next available
numeric key is used. In other words by the time you are trying to work out
what the keys are you've already passed a really bad bug in your code -
either assign all your array values with PHP working out the indices, or
specify all the keys yourself. Mixing the two together, particularly if you
want to use numeric keys, is just asking for trouble.

C.
Apr 27 '06 #3

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

Similar topics

2
by: Tommo | last post by:
Hello All, I have a slight problem that goes like this. I have created a Perl hash where the keys are made up of numeric values, I was then sorting the 'keys' for this hash on their value (a<=>b...
54
by: Victor Mehta | last post by:
would it matter if I decided to make a primary key a string of numbers vs actual numbers ? would it make any difference to DB2 in terms of efficiency ? why would you choose numeric over a string...
12
by: Alex | last post by:
I have a question about determining if one QueryString keys exists. The idea is, if this key exists, than its presence is enough to indicate that its value is true. For example ... ...
1
by: Dino Buljubasic | last post by:
Hi, Can somebody help me with this problem please. I need to get the value, not just to check for it, of a number pressed but it has to work for both, numbers above QUERTY and numbers entered...
4
by: Brian Blais | last post by:
Hello, Most of my experience is with Matlab/Octave, so I am a Python newbie (but enjoying it! :) ) There are a lot of things that I do in Matlab that I'd like to know the proper way to do in...
5
by: Reny | last post by:
can any one tell how can i restrict my user to type just numeric character in the textbox.I am using VS.NET 2003 (VB.NET)
11
by: John | last post by:
I am coding a radix sort in python and I think that Python's dictionary may be a choice for bucket. The only problem is that dictionary is a mapping without order. But I just found that if the...
10
by: John Dann | last post by:
I'm new to Python and can't readily find the appropriate function for the following situation: I'm reading in a byte stream from a serial port (which I've got working OK with pyserial) and which...
16
by: pupilstuff | last post by:
hi guys i just want to perform custom paging in which at the footer of the grid view ,there must be a pager 'pervious/next with numeric' this is what i did in aspx page <asp:GridView...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.