Jump to content

arrays in C vs arrays in PHP


johnmerlino1

Recommended Posts

Arrays in C are fixed length:

#define MAX_SIZE 5

int main(void){
  int n[ 5 ]; 
  for(int i=0;i<MAX_SIZE;i++){
    n[i]=i;
  }
  return 1;
}

If I try to insert an eleement into the array, it will result in undefined behavior.

 

Java compensates for this by creating an actual object class called ArrayList or LinkedList, the former an internal store of array elements that dynamically resizes and the latter just a node tree with pointers to next and previous elements.

ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(1);
arr.add(2);

It seens that the array() construct in PHP is not a function or a class but an internal construct. How does it dynamically resize arrays?

Link to comment
https://forums.phpfreaks.com/topic/290138-arrays-in-c-vs-arrays-in-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.