?
Solved

PHP array index storage (efficiency) question

Posted on 2011-02-26
4
Medium Priority
?
336 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 664 total points
ID: 34988220
I believe associative. As you can use text and whatnot for keys.
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 668 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 668 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

764 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