Creating Arrays
Use array();
Create an empty array
$result_search = array();
//You can add items to it like this:
$result_search[] = "a";
$result_search[] = "b";
$array = array_fill(0, 24, 0); //Fill an array from index 0, 24 items long, with default value 0
Create an array of values
$names = array('Adam', 'Bill', 'Charlie);
echo $names[1]; //Displays Bill
Key & Value Arrays
$MyKeyValueArray = array(
'comments' => $comments_count,
'responses' => $responses_count
);
or create like this
$MyKeyValueArray = array();
$MyKeyValueArray['comments'] = $comments_count;
$MyKeyValueArray['responses'] = $responses_count;
Accessing the array keys and values
foreach ($MyKeyValueArray as $Key => $Value)
{
echo "{$Key} => {$Value} ";
}
foreach ($MyArray as $Item)
{
}
Two Dimension Arrays
$MyArray = array(
array('1', '2', '3', '4'),
array('10', '20', '30', '40'),
array('100', '200', '300', '400'));
echo $MyArray[1][2]; //Displays 30
$MyArray = array(
$array = array_fill(0, 24, false), //Fill an array from index 0, 24 items long, with default value false
$array = array_fill(0, 24, false),
$array = array_fill(0, 24, false),
);
You can carry on creating arrays within arrays if desired.
Accessing Array Values
$my_val = $my_array[0][video_index];
Array Length
count(MyArray)
Is Array?
if (!is_array($my_array))
Is Array Empty
if (empty($my_array))
Does array index exist?
if (isset($matches[1]))
{
//Another example
return isset($args['v']) ? $args['v'] : false;
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.