Home >Backend Development >PHP Tutorial >PHP array summary (1)_PHP tutorial

PHP array summary (1)_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 15:49:30927browse

Array
1. The subscript of the array is an integer value or a string type.
eg1. The keys of indexed arrays are ______, and the keys of associative arrays are ______.
2. When a string is used as an index, quotation marks should be added. Constants or variables do not need to be quoted, otherwise they will not compile.
In PHP, a string without quotes will automatically generate a bare string, and PHP may define this constant later. Unfortunately, if you have the same name in your code, then the string will be reassigned. .
eg2.// Display all errors
error_reporting(E_ALL);
$arr = array('fruit' => 'apple', 'veggie' => ' carrot');
// Correct
print $arr['fruit']; // apple
print $arr['veggie']; // carrot
// Incorrect. This works but also throws a PHP error of
// 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','veggie');
// 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 for
print "Hello {$arr[fruit]}"; // Hello carrot
print "Hello {$arr[' fruit']}"; // Hello apple
// This will not work, results in a parse error such as:
// 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 problem
$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 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 continuedTo be continuedTo be continued------
15.array_combine
16array_count_values ​​
17.array_diff
18.array_filter
19.array_search

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319512.htmlTechArticleArray 1. The subscript of the array is an integer value or a string type. eg1. The keys of indexed arrays are ______, and the keys of associative arrays are ______. 2. When a string is used as an index, quotation marks should be added...
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