Php array summary (1 ). Array 1. the subscript of the array is an integer value or a string type. The key of the eg1. index array is ______, and the key of the associated array is ______. 2. when a string is used as an index, an array of quotation marks should be added.
1. the subscript of the array is an integer value or a string type.
The key of the eg1. index array is ______, and the key of the associated array is ______.
2. when the string is used as an index, quotation marks should be added. Constants or variables cannot be compiled without quotation marks.
In php, a string without quotation marks will automatically generate a bare string, and PHP may define this constant later. Unfortunately, your code has the same name, then the string is assigned a value again.
Eg2. // Display all errors
Error_reporting (E_ALL );
$ Arr = array ('fruit' => 'apple', 'veggi' => 'carrot ');
// Correct
Print $ arr ['fruit']; // apple
Print $ arr ['veggi']; // carrot
// Incorrect. This works but also throws a PHP error
// Level E_NOTICE because of an undefined constant named fruit
//
// Notice: Use of undefined constant fruit-assumed 'fruit' in...
Print $ arr [fruit]; // apple
// Let's define a constant to demonstrate what's going on. We
// Will assign value 'veggie' to a constant named fruit.
Define ('fruit', 'veggi ');
// Notice the difference now
Print $ arr ['fruit']; // apple
Print $ arr [fruit]; // carrot
// The following is okay as it's inside a string. Constants are not
// Looked for within strings so no E_NOTICE error here
Print "Hello $ arr [fruit]"; // Hello apple
// With one exception, braces surrounding arrays within strings
// Allows constants to be looked
Print "Hello {$ arr [fruit]}"; // Hello carrot
Print "Hello {$ arr ['fruit']}"; // Hello apple
// This will not work, results in a parse error such:
// Parse error: parse error, expecting T_STRING 'or T_VARIABLE' or T_NUM_STRING'
// This of course applies to using autoglobals in strings as well
Print "Hello $ arr ['fruit']";
Print "Hello $ _ GET ['foo']";
// Concatenation is another option
Print "Hello". $ arr ['fruit']; // Hello apple
?>
3. key value issues
$ A ['color'] = 'red ';
$ A ['taste '] = 'sweet ';
$ A ['shape'] = 'round ';
$ A ['name'] = 'apple ';
$ A [] = 4; // key will be 0
$ B [] = 'a'; // key will be 0
$ B [] = 'B'; // key will be 1
$ B [] = 'C'; // key will be 2
Switching = array (10, // key = 0
5 => 6,
3 => 7,
'A' => 4,
11, // key = 6 (maximum of integer-indices was 5)
'8' => 2, // key = 8 (integer !)
'02' => 77, // key = '02'
0 => 12 // the value 10 will be overwritten by 12
);
$ Multi_array = array ("red ",
"Green ",
42 => "blue", "yellow" => array ("apple", 9 => "pear", "banana", "orange" => array ("dog ", "cat", "iguana ")));
?>
A. $ multi_array ['yellow'] ['apple'] [0]
B. $ multi_array ['blue'] [0] ['Orange '] [1]
C. $ multi_array [3] [3] [2]
D. $ multi_array ['yellow'] ['Orange '] ['cat']
E. $ multi_array ['yellow'] ['Orange '] [1]
-------------------------------- To be continued ------
4. array_walk
5. var_dump
6. array_intersect
7. array_sum
8. array_count_values
9. array_flip
10. natsort
11. ksort (), asort (), krsort (), sort (), usort ()
12. array_reverse ()
13. array_merge
14. reset
------------------------------- To be continued ------
15. array_combine
16array_count_values
17. array_diff
18. array_filter
19. array_search
Limit 1. the subscript of the array is an integer value or a string type. The key of the eg1. index array is ______, and the key of the associated array is ______. 2. when the string is used as an index, quotation marks should be added...