Skip to content
Advertisement

What kind of array does PHP use?

I can define an array in PHP like this:

JavaScript

In C++, we have two kinds of array.

  1. The first kind is a fixed size array, for example:

    JavaScript
  2. The second kind is a dynamic sized array

    JavaScript

What kind of array does PHP use? Are both kinds of arrays in PHP? If so, can you give me examples?

Advertisement

Answer

PHP is not as strict as C or C++. In PHP you don’t need to specify the type of data to be placed in an array, you don’t need to specify the array size either.

If you need to declare an array of integers in C++ you can do it like this:

int array[6];

This array is now bound to only contain integers. In PHP an array can contain just about everything:

JavaScript

If you’re coming from a C++ background it’s best to view the PHP array as a generic vector that can store everything.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement