Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6741857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:46:30+00:00 2026-05-26T11:46:30+00:00

If I am creating an array with several hundred indexes, how much overhead is

  • 0

If I am creating an array with several hundred indexes, how much overhead is required for the additional array versus adding a second dimension to an existing array?

I.E. $pages[‘page’][‘url’] and $titles[‘page’][‘title’] versus $pages[‘page’][‘url’][‘title’] versus $pages[‘page’][‘title’], where the last example assumes each index of $pages contains an associative array.

The goal is to be able to be to lookup two attributes of each ‘page’. Each ‘page’ has a ‘url’ and a ‘title’, which would be more efficient for memory usage on the arrays? Which for access/storing the data?

Two associative arrays:

// Store the information in arrays
$titles['page1'] = 'Page 1 Title';
$titles['page2'] = 'Page 2 Title';

$urls['page1'] = 'http://www.page1.com';
$urls['page2'] = 'http://www.page2.com';

// Display an example
echo $titles['page1'] . ' is at ' . $urls['page1']; 

or one array of arrays:

$pages['page1'] = array( 'title' => 'Page 1 Title', 'url' => 'http://www.page1.com' );
$pages['page2'] = array( 'title' => 'Page 2 Title', 'url' => 'http://www.page2.com' );

// Display an example
echo $pages['page1']['title'] . ' is at ' . $pages['page1']['url'];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:46:31+00:00Added an answer on May 26, 2026 at 11:46 am

    The memory usage of a two dimensional array is slightly bigger, but this may result from bad code (?).

    <!--
        http://php.net/manual/en/function.memory-get-usage.php
    
        array1: 116408 (1D 1001 keys)     (1x 100.000 keys:  11.724.512)
        array2: 116552 (2D, 1002 keys)    (2x  50.000 keys:  11.724.768)
    
        total:    +144                                             +256
    -->
    
    <?php
    
    function genRandomString() {
        $length = 10;
        $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
        $string = '';    
    
        for ($p = 0; $p < $length; $p++) {
            $string .= $characters[mt_rand(0, strlen($characters))];
        }
    
        return $string;
    }
    
    $i = 0;
    
    // ----- Larger 1D array -----
    $mem_start = memory_get_usage();
    echo "initial1: " . $mem_start . "<br />";
    $arr = array();
    
    for ($i = 1; $i <= 1000; $i++) {
        $arr[ genRandomString() ] = "Hello world!";
    }
    
    echo "array1: " . (memory_get_usage() - $mem_start) . "<br />";
    unset($arr);
    
    // ----- 2D array -----
    $mem_start = memory_get_usage();
    $arr2 = array();
    
    echo "initial2: " . $mem_start . "<br />"; 
    
    
    for ($i = 1; $i <= 500; $i++) {
        $arr2["key______1"][ genRandomString() ] = "Hello world!";
        $arr2["key______2"][ genRandomString() ] = "Hello world!";
    }
    
    echo "array2: " . (memory_get_usage() - $mem_start) . "<br />";
    
    unset($arr2);
    
    unset($i);
    unset($mem_start)    
    echo "final: " . memory_get_usage() . "<br />"; 
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an array of string objects in PowerShell which needs to be
Why is it that for user defined types when creating an array of objects
When creating a 3D array in C#, which is a better way to create
I'm creating a numpy array which is to be filled with objects of a
If you are creating a 1d array in Python, is there any benefit to
What is the prefered method for creating a byte array from an input stream?
i'm attempting to instantiate a bunch of sounds by creating a string array containing
I'm creating my own JavaScript Array-like object and I have methods that call closures.
I'm creating a bot in Shell Script: # Array with expressions expressions=("Ploink Poink" "I
How can you put an array to the WHERE -clause below without creating 50

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.