您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php数组 php数组总结篇一)

2024/3/1 22:22:17发布18次查看
数组
1.数组的下标是整型数值或者是字符串类型。
eg1.索引数组的键是______,关联数组的键是______。
2.字符串作为索引的时候,应加上引号。常量或者变量不用加引号,否则无法编译。
在php中,没有引号的字符串会自动生成一个裸字符串,而 php 可能会在以后定义此常量,不幸的是你的代码中有同样的名字,那么这个字符串就被重新赋值。
eg2. 'apple', 'veggie' => 'carrot');
// 正确
print $arr['fruit']; // apple
print $arr['veggie']; // carrot
// 不正确。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.键值问题
$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
);
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]
--------------------------------待续待续待续------
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
-------------------------------待续待续待续------
15.array_combine
16array_count_values
17.array_diff
18.array_filter
19.array_search
以上就介绍了php数组 php数组总结篇一),包括了php数组方面的内容,希望对php教程有兴趣的朋友有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product