• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

PHP array index storage (efficiency) question

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
willsherwood
Asked:
willsherwood
3 Solutions
 
Aaron TomoskyTechnology ConsultantCommented:
I believe associative. As you can use text and whatnot for keys.
0
 
Dave BaldwinFixer of ProblemsCommented:
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
 
DanDauchyCommented:
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
 
willsherwoodAuthor Commented:
thanks all!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now