"Simon", 2 => "Elaine"); //Creation of array echo $array["key1"]; //Output Simon echo $array[2]; //Output Elaine ?> Copy the code as follows: array (0"/> "Simon", 2 => "Elaine"); //Creation of array echo $array["key1"]; //Output Simon echo $array[2]; //Output Elaine ?> Copy the code as follows: array (0">

Home >Backend Development >PHP Tutorial >Implement the ideal idiom php array creation, calling and updating implementation code

Implement the ideal idiom php array creation, calling and updating implementation code

WBOY
WBOYOriginal
2016-07-29 08:39:251066browse

Copy code The code is as follows:


$array = array("key1" => "Simon", 2 => "Elaine"); //Creation of array
echo $ array["key1"]; //Output Simon
echo $array[2]; //Output Elaine
?>


Copy code The code is as follows:


$array = array("key1" => array(0 => 1, 1 => 10, 2 => 100),
"key2" => array(0 => 5, 1 => 25 , 2 => 125));
echo $array["key1"][0]; //Output 1
echo $array["key1"][1]; //Output 10
echo $array["key1 "][2]; //Output 100
echo $array["key2"][0]; //Output 5
echo $array["key2"][1]; //Output 25
echo $array[" key2"][2]; //Output 125
?> => 1, 1 => 10, 2 => 100), //Define the array
"key2" => array(0 => 5, 1 => 25, 2 => 125)) ;

print_r($array); //Output array
?>

Copy code


The code is as follows:


$array = array("a", "b", "c"); //Define array
print_r($array); //Output array

?>

Copy code

The code is as follows:


$array = array( "a", "b","c"); //Define array
$array[0] = "Simon"; //Modify array elements

print_r($array); //Output array
?>

The above introduces the creation, calling and updating implementation code of the ideal idiom PHP array, including the content of realizing the ideal idiom. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn