-2

I only wanted to know what is an array.

An array is a collection of items of same data type stored at contiguous memory locations.

This is what I got

Just in simple words

0

2 Answers 2

1

Arrays are like boxes : If you declare an array of integer with 5 in size, you can have have 5 integer in it. If you wish to select the first item, you have to take the 0, then the second is 1, the next is 2 etc... And the last is 4 (because you begin at 0). To put it simple, the last integer of your array is always : the size of your array (here is 5) minus one (last integer is 4).

1

At a basic level, an array is just data that scripts can understand as separated.

Lets say I made an array of numbers in PHP like this:

$arrayornumbers = Array(10,21,32,44);

It isn't read like a string of text '10,21,32,44' but instead, it's known that they're 4 separate numbers.

I could then loop through them and add 4 to each of them individually:

foreach($arrayofnumbers as $number){
echo $number + 4;
}

An array can be much more advanced, with nested arrays, or in other words, arrays inside arrays, which I like to think of as folders with files in. Also you can use them for any data type, not just numbers. Hope this helps.

Not the answer you're looking for? Browse other questions tagged or ask your own question.