Solved

PHP array index storage (efficiency) question

Posted on 2011-02-26
4
335 Views
Last Modified: 2012-05-11
I have a web form with input fields that have  (POST)  name variables that are an array.
The numeric array indexes are best for me if they are sparse (powers of 2).
In PHP are numeric array indices associative or true contiguous array vectors?
i.e., is it inefficient for either storage or execution time to utilize sparse array indexes?
(if needed i can change to contiguous, but would rather not if all else is the same)

<input ...  name=A[1]... />
<input ...  name=A[2]... />
<input ...  name=A[4]... />
...
<input ...  name=A[1048576]... />

and sample usage once in PHP
$_POST['A'][index]
and
array_sum($_POST['A'])

please advise

thanks
0
Comment
Question by:willsherwood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 39

Assisted Solution

by:Aaron Tomosky
Aaron Tomosky earned 166 total points
ID: 34988220
I believe associative. As you can use text and whatnot for keys.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 167 total points
ID: 34988323
From http://us2.php.net/manual/en/language.types.array.php , "An array in PHP is actually an ordered map."  Details on that page.
0
 
LVL 4

Assisted Solution

by:DanDauchy
DanDauchy earned 167 total points
ID: 34988328
I believe it is associative. ie when you create an array at index 1 and then 100, it doesn't fill in the middle w/ padding.  

for storage, it is not inefficient to have an array at 1 and 100 because it only allocates enough memory for those 2 elements.  

for execution time it is not any more or less efficient because you are simply offsetting the start of that array with a number (as you would from index 1 to 2 or from 1 to 100).  Even if it was a contiguous array it would make no difference on execution time.
0
 

Author Closing Comment

by:willsherwood
ID: 34988709
thanks all!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question