What is Array?
An array in PHP is actually an ordered map, what is a map? A map is a type that associates values to the keys, you can consider as list, stack, hash table, dictionary or an array. An array can be created with the help of array() language construct. It takes number of parameters in the form of key=>value pair separated by comma.
General format of an array is:
An example of an array is given below:
$first=array('Name' =>'Rose', 18=>"true");
Output of the above example is:
In above example
<?php ?> is the delimiter, which is mandatory for any PHP program.
$first is the name of the variable
array() is the language construct
'Name' and 18 are the keys, here character type keys should be enclosed within single or double quote and these are case sensitive, if you declare a key as 'Name' and if you write 'name' to access that key then an error message will be generated,
echo is the language construct
$first['Name'] is the actual way to access the array.
' . ' operator is used to concatenate strings.
<br/> is used to break line
Each line should be ended with a semicolon but at the last line it is optional.
A key may be either an integer or string, floats in the key are truncated to integer.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.