数组与数据结构:
1.array_pop();
删除数组中最后一个值.
**
<?php
$arr=array(
'title1'=>'linux',
'title2'=>'java',
'title3'=>'php',
'title4'=>'js',
'title5'=>'shell',
'title6'=>'python',
'title7'=>'ruby',
'title8'=>'c++',
);
array_pop($arr);
echo '<pre>';
print_r($arr);
echo '</pre>';
?>
结果是
Array
(
[title1] => linux
[title2] => java
[title3] => php
[title4] => js
[title5] => shell
[title6] => python
[title7] => ruby
)
2.array_push();
从数组的最后插入一个值.
**
<?php
$arr=array(
'title1'=>'linux',
'title2'=>'java',
'title3'=>'php',
'title4'=>'js',
'title5'=>'shell',
'title6'=>'python',
'title7'=>'ruby',
'title8'=>'c++',
);
array_push($arr,'rrr');
echo '<pre>';
print_r($arr);
echo '</pre>';
?>
结果是
Array
(
[title1] => linux
[title2] => java
[title3] => php
[title4] => js
[title5] => shell
[title6] => python
[title7] => ruby
[title8] => c++
[0] => rrr
)
3.array_shift();
删除数组中第一个值.
**
<?php
$arr=array(
'title1'=>'linux',
'title2'=>'java',
'title3'=>'php',
'title4'=>'js',
'title5'=>'shell',
'title6'=>'python',
'title7'=>'ruby',
'title8'=>'c++',
);
array_shift($arr);
echo '<pre>';
print_r($arr);
echo '</pre>';
?>
结果是
Array
(
[title2] => java
[title3] => php
[title4] => js
[title5] => shell
[title6] => python
[title7] => ruby
[title8] => c++
)
4.array_unshift();
从数组的第一个位置插入一个值.
**
<?php
$arr=array(
'title1'=>'linux',
'title2'=>'java',
'title3'=>'php',
'title4'=>'js',
'title5'=>'shell',
'title6'=>'python',
'title7'=>'ruby',
'title8'=>'c++',
);
array_unshift($arr,'rrr');
echo '<pre>';
print_r($arr);
echo '</pre>';
?>
结果是
Array
(
[0] => rrr
[title1] => linux
[title2] => java
[title3] => php
[title4] => js
[title5] => shell
[title6] => python
[title7] => ruby
[title8] => c++
)