What is the difference between a string and an array?
Array | String |
---|---|
This is a sequential collection of elements having the same data type. | This is a sequence of characters presented as a single data type. |
Elements of the array are stored in a continuous manner to optimize memory locations space. | Strings can be stored in any manner. |
It can store floats, integers, doubles, etc. | Strings can only hold char data types. |
Arrays are mutable, i.e., values can be changed later on. | Strings are immutable, i.e., values cannot be changed once created. |
It can be one or two dimensional. | It is only two dimensional. |
The length of an array once created is fixed. | The length of a string can be changed later on. |
Related Article: Important Array Functions in PHP
BY Best Interview Question ON 18 Nov 2020