johnmerlino1 Posted July 27, 2014 Share Posted July 27, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/290138-arrays-in-c-vs-arrays-in-php/ Share on other sites More sharing options...
CroNiX Posted July 27, 2014 Share Posted July 27, 2014 There are no constraints on arrays in php. If you add and element to an array it just adds the element to the end of the array, unless you specify the index. Quote Link to comment https://forums.phpfreaks.com/topic/290138-arrays-in-c-vs-arrays-in-php/#findComment-1486258 Share on other sites More sharing options...
bsmither Posted July 28, 2014 Share Posted July 28, 2014 (edited) I would say array() is a 'language construct' and may best be thought of as a stack. Edited July 28, 2014 by bsmither Quote Link to comment https://forums.phpfreaks.com/topic/290138-arrays-in-c-vs-arrays-in-php/#findComment-1486286 Share on other sites More sharing options...
trq Posted July 28, 2014 Share Posted July 28, 2014 Who cares? 1 Quote Link to comment https://forums.phpfreaks.com/topic/290138-arrays-in-c-vs-arrays-in-php/#findComment-1486288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.