Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:数组函数众多, 分类记忆比较好
<?php
//索引数组
$customer = [
1=>'001',
2=>'张三',
3=>35,
4=>'32050219840925301X'
];
printf('<pre>%s</pre>', print_r($customer, true));
?>
Array
(
[1] => 001
[2] => 张三
[3] => 35
[4] => 32050219840925301X
)
<?php
//关联数组
$customer = [
'id'=>'001',
'name'=>'张三',
'age'=>35,
'ID card'=>'32050219840925301X'
];
printf('<pre>%s</pre>', print_r($customer, true));
?>
Array
(
[id] => 001
[name] => 张三
[age] => 35
[ID card] => 32050219840925301X
)
<?php
//索引数组
$customer = [
1=>'001',
2=>'张三',
3=>35,
4=>'32050219840925301X'
];
printf('<pre>%s</pre>', print_r($customer, true));
echo '<hr>';
printf('[%s]=>%s<br>', key($customer), current($customer));
next($customer);
printf('[%s]=>%s<br>', key($customer), current($customer));
next($customer);
printf('[%s]=>%s<br>', key($customer), current($customer));
next($customer);
printf('[%s]=>%s<br>', key($customer), current($customer));
?>
Array
(
[1] => 001
[2] => 张三
[3] => 35
[4] => 32050219840925301X
)
[1]=>001
[2]=>张三
[3]=>35
[4]=>32050219840925301X
<?php
//索引数组
$customer = [
1=>'001',
2=>'张三',
3=>35,
4=>'32050219840925301X'
];
printf('<pre>%s</pre>', print_r($customer, true));
echo '<br>';
while(true){
printf('[%s]=>%s<br>', key($customer), current($customer));
if(next($customer)) continue;
else break;
}
?>
Array
(
[1] => 001
[2] => 张三
[3] => 35
[4] => 32050219840925301X
)
[1]=>001
[2]=>张三
[3]=>35
[4]=>32050219840925301X
<?php
//关联数组
$customer = [
'id'=>'001',
'name'=>'张三',
'age'=>35,
'ID card'=>'32050219840925301X'
];
printf('<pre>%s</pre>', print_r($customer, true));
echo '<br>';
//echo count($customer);
for($i = 0; $i < count($customer); $i++){
printf('[%s]=>%s<br>', key($customer), current($customer));
next($customer);
}
Array
(
[id] => 001
[name] => 张三
[age] => 35
[ID card] => 32050219840925301X
)
[id]=>001
[name]=>张三
[age]=>35
[ID card]=>32050219840925301X
<?php
//关联数组
$customer = [
'id'=>'001',
'name'=>'张三',
'age'=>35,
'ID card'=>'32050219840925301X'
];
printf('<pre>%s</pre>', print_r($customer, true));
echo '<br>';
foreach($customer as $value) {
echo $value, '<br>';
}
?>
Array
(
[id] => 001
[name] => 张三
[age] => 35
[ID card] => 32050219840925301X
)
001
张三
35
32050219840925301X
<?php
//关联数组
$customer = [
'id'=>'001',
'name'=>'张三',
'age'=>35,
'ID card'=>'32050219840925301X'
];
printf('<pre>%s</pre>', print_r($customer, true));
echo '<br>';
foreach($customer as $key) {
printf('[%s]=>%s<br>', $key, $value);
}
?>
Array
(
[id] => 001
[name] => 张三
[age] => 35
[ID card] => 32050219840925301X
)
[001]=>
[张三]=>
[35]=>
[32050219840925301X]=>
array_keys()
<?php
$customer = [
'id'=>'001',
'name'=>'张三',
'age'=>35,
'ID card'=>'32050219840925301X'
];
print_r(array_keys($customer));
?>
Array ( [0] => id [1] => name [2] => age [3] => ID card )
array_key_exists()
<?php
$customer = [
'id'=>'001',
'name'=>'张三',
'age'=>35,
'ID card'=>'32050219840925301X'
];
echo array_key_exists('sex',$customer) ? '存在':'不存在';
?>
不存在
array_values()
<?php
$customer = [
'id'=>'001',
'name'=>'张三',
'age'=>35,
'ID card'=>'32050219840925301X'
];
printf('<pre>%s</pre>', print_r(array_values($customer), true));
?>
Array
(
[0] => 001
[1] => 张三
[2] => 35
[3] => 32050219840925301X
)
array_search()
<?php
$customer = [
'id'=>'001',
'name'=>'张三',
'age'=>35,
'ID card'=>'32050219840925301X'
];
var_dump(array_search('35', $customer));
?>
string(3) "age"
array_unique()
<?php
$customer = [
'1'=>'001',
'2'=>2,
'3'=>2,
'4'=>'123'
];
print_r(array_unique($customer));
?>
Array ( [1] => 001 [2] => 2 [4] => 123 )