- $arr = Array ("a" = = 1, "b" = 2, "c" = 3);
Copy CodeIf this defines an array, it will report a compilation error:
- $arr = Array ("A" = 1, "b" = 2, "c" = 3);
Copy CodeTherefore, when you define an array, you can only use the = 2,
- $arr = Array ("a" = = 1, "b" = 2, "c" = 3);
- echo $arr [0];
- echo $arr [1];
Copy CodeIt was a blank shot. The correct way to print:
- echo $arr ["a"];
Copy Code3, add elements or modify the elements can only use =, can not use =
- $arr = Array ("a" = = 1, "b" = 2, "c" = 3);
- $arr ["c"] = 6;
Copy CodeThe above operation method, in PHP 5.2.5 will appear the compilation error Add elements or modify elements to write this:
- $arr = Array ("a" = = 1, "b" = 2, "c" = 3);
- $arr ["D"] = 4;
- $arr ["c"] = 6;
Copy CodeTo delete an element, use unset:
- unset ($arr ["C"]);
Copy Code4, think of the following code, what will output?
- $arr = Array ("a" = =, "b" = 3,4);
- $arr [] = 5;
- foreach ($arr as $key = $value)
- {
- echo "Key: $key value: $value
";
- }
Copy CodeOutput Result:
- $arr = Array ("a" = = 1,3, "b" = 2);
- After the array is created, the default pointer refers to the first element
- Echo current ($arr). "
";
- Move forward a position
- Echo Next ($arr). "
";
- The default rule for grooming is small to large
- Sort ($arr);
- After finishing the array pointer again stops at the first element
- Echo current ($arr). "
";
- Echo Next ($arr). "
";
- Back one position
- Echo prev ($arr). "
";
Copy CodeOutput results: 13121 |