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 8199453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:10:16+00:00 2026-06-07T06:10:16+00:00

Here’s an array in Java: int[] myArray = new int[3]; myArray[0] = 0; myArray[1]

  • 0

Here’s an array in Java:

int[] myArray = new int[3];
myArray[0] = 0;
myArray[1] = 1;
myArray[2] = 2;

The first line immediately reserves 3 consecutive blocks of memory. Creating a fourth element would actually require creating a new array with int[4], and then transferring values from index 0 to 2 into the new array. Such as the following:

int[] mySecondArray = new int[4];
for (int i = 0; i < myArray.length; i += 1) {
    mySecondArray[i] = myArray[i];
}
mySecondArray[3] = 3;

But in PHP, we can declare an array, and simply add another element without all the fuss that a Java requires.

$my_array = array(0, 1, 2);
$my_array[] = 4;

Does PHP actually take care of creating a new array after pushing an additional element onto an existing array? Or are PHP arrays actually not the same (in terms of memory) as arrays in languages such as C and Java? I’m a little concerned, because I see a lot of PHP code that iterates through a loop and appends 50+ new elements onto an existing array, which would be utterly ridiculous to do in Java.

  • 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-06-07T06:10:18+00:00Added an answer on June 7, 2026 at 6:10 am

    Or are PHP arrays actually not the same (in terms of memory) as arrays in languages such as C and Java?

    In PHP arrays are in fact hash tables. However, the memory management is hardly comparable, because they are two completely different languages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
Here is my persistence.xml : <?xml version=1.0 encoding=UTF-8?> <persistence xmlns=http://java.sun.com/xml/ns/persistence xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd version=1.0>
here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is a code snippet I was working with: int *a; int p =
Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
here is my code, SiteMember class @OneToMany(mappedBy = member,cascade=CascadeType.ALL) private List<MemberThread> memberThread = new
Here is the error: 07-30 16:57:08.613: E/AndroidRuntime(655): java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1 07-30 16:57:08.613: E/AndroidRuntime(655): at
Here is my string line: string conSTR = Data Source=(local);Initial Catalog=MyDB;User ID=sa; I just
here is my click listner... mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View

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.