Home > Article > Backend Development > Simple entry case for PHP array
Arrays can store one or more values in separate variable names. This article mainly shares with you a simple entry-level case of PHP arrays, hoping to help you.
<?php //普通声明 $arr = array('aaa','bbbb','ccccc'); echo $arr[0],'<br>'; echo $arr[2],'<br>','<br>'; $arr1[] = 'xxxx'; $arr1[] = 'yyyyy'; print_r($arr1); //键值对方式声明数组。 $kv = array('name'=>'张三','sex'=>'男','age'=>18); echo $kv['name'],'<br>'; echo $kv['sex'],'<br>'; echo $kv['age'],'<br>'; //数组声明二 $skv['x'] = 'xxxx'; $skv['y'] = 'yyyyy'; print_r($skv); echo '<br>'; //特殊情况:字符串‘10’ 和 数字10 在数组中会转换成数字10 。 $test['10'] = '张三'; $test[10] = '丽丽'; $test['10.0'] = '隔壁';//加小数点后的字符串不会被转换成数字。*** //小数会取整后,都是9 同样会覆盖。 $test[9.12] = '老王'; $test[9.14] = '丽丽'; //'' 在数组中等同意 null 也会被覆盖 $test[''] = '马云'; $test[null] = '丽丽'; print_r($test); //通过 extract 函数 将数组中的变量,导出成对象和值: extract($kv); echo '<br>',$name,'<br>',$sex,'<br>',$age;?>
The output is as follows:
aaa cccccArray ( [0] => xxxx [1] => yyyyy ) 张三 男18Array ( [x] => xxxx [y] => yyyyy ) Array ( [10] => 丽丽 [10.0] => 隔壁 [9] => 丽丽 [] => 丽丽 ) 张三 男18
Related recommendations:
Summary of PHP array sorting method
PHP arrays and characters Methods for converting between strings
php Definition and usage of array function current()
The above is the detailed content of Simple entry case for PHP array. For more information, please follow other related articles on the PHP Chinese website!