Tools, FAQ, Tutorials:
Creating an Array in PHP
How To Create an Array in PHP?
✍: FYIcenter.com
You can create an array using the array() constructor. When calling array(), you can also initialize the array with pairs of keys and values. Here is a PHP script on how to use array():
<?php
print("Empty array:\n");
$emptyArray = array();
print_r($emptyArray);
print("\n");
print("Array with default keys:\n");
$indexedArray = array("PHP", "Perl", "Java");
print_r($indexedArray);
print("\n");
print("Array with specified keys:\n");
$mappedArray = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java");
print_r($mappedArray);
print("\n");
?>
This script will print:
Empty array:
Array
(
)
Array with default keys:
Array
(
[0] => PHP
[1] => Perl
[2] => Java
)
Array with specified keys:
Array
(
[Zero] => PHP
[One] => Perl
[Two] => Java
)
⇒ Testing If a Variable Is an Array in PHP
2016-10-15, ∼2406🔥, 0💬
Popular Posts:
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...
How to use the "forward-request" Policy Statement to call the backend service for an Azure API servi...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...
How To Copy Array Values to a List of Variables in PHP? If you want copy all values of an array to a...
How to install .NET Framework in Visual Studio Community 2017? I have the Visual Studio Installer in...