Solved

PHP array index storage (efficiency) question

Posted on 2011-02-26
4
332 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
4 Comments
 
LVL 38

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

809 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