Ok, even some developers who already understand php a little are always confused about arrays and don’t really know how to use them. In this lessons, we will try to cover the basic uses of Arrays in PHP.
When you declare a variable, it can only hold one value. Like the example below:
<?php
$my_variable = "This is some text";
?>
As you can see, it can only store “This is some text”, or a single value. But what if you have to store multiple values which have some relationship between them? Let’s take an example from the previous lesson, remember our guy named John? We declared his age. Let’s say we want to add his name, location etc. We can do it like this:
$persons_age = ’16’;
$persons_name = ‘John’;
$persons_location = ‘California’;
But with the use of arrays, you can store all of that information in one variable. Like below:
<?php
$persons = array('John','16','California');
?>
Continue Reading »