亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP commonly used array manipulation functions

We have many elements that operate on arrays, let’s talk about some of them first in this section. In 6.3 we will summarize more common array functions.

The following functions are mainly used to move the array pointer and push in and pop out array elements.

##array_shiftPop array The first element inarray_unshiftPush the element at the beginning of the arrayarray_pushPush elements to the end of the arrayarray_popPop the last element at the end of the arraycurrentRead the value of the current position of the pointer#keyRead the key of the current position of the pointer nextMove the pointer downprevMove upresetPointer to the beginningendPointer to the end

array_shift

##mixed array_shift ( array &$array )

Function: Pop the first element in the array

<?php
$mingren = array("鄧超", "黃曉明", "寧澤濤", "鐘漢良");
$dc = array_shift($mingren);

echo $dc .'<br />';

print_r($mingren);
?>

Execution result:


QQ截圖20161114134130.png

Conclusion:

1. Pop out the first array element, changing the result of the original array

2. The pop-up value is assigned to $dc

array_unshift

int array_unshift (array &$array, mixed $value 1 [, mixed $... ] )

Function: Push one or more elements to the beginning of the index array, and return the total number.

<?php
$mingren = array("鄧超", "黃曉明");
$dc = array_unshift($mingren , "寧澤濤", "鐘漢良");

echo $dc .'<br />';

print_r($mingren);
?>

The execution results are as follows:

QQ截圖20161114134218.png

array_pop

mixed array_pop (array &$array)

Function: pop up an element at the end of the array

<?php
$mingren = array("鄧超", "黃曉明", "寧澤濤", "鐘漢良");
$dc = array_pop($mingren);

echo $dc .'<br />';

print_r($mingren);
?>

Execution result:


QQ截圖20161114134302.png

array_push

##int array_push ( array &$array , mixed $value1 [, mixed $... ] )

Function: Push one or more elements to the end of the index array, and return the total number.

<?php
$mingren = array("鄧超", "黃曉明");
$dc = array_push($mingren , "寧澤濤", "鐘漢良");

echo $dc .'<br />';

print_r($mingren);
?>

Execution result:


QQ截圖20161114134336.png

#current,key,prev,next,reset function demonstration

The functions of these functions have been explained very clearly. We demonstrate through code:

<?php
$t=array(
   '我們',
   'yy'=>'永遠(yuǎn)',
   'dbg'=>'需要不斷奮進(jìn)',
   'djn'=>'才能開(kāi)創(chuàng)未來(lái)'
   );


//讀取數(shù)組的值
echo current($t).'<br />';
//讀取數(shù)組的鍵
echo key($t).'<br />';

//向后移動(dòng)一下
next($t);

//再讀值和鍵
echo current($t).'<br />';

echo key($t).'<br />';


//向后移動(dòng)一下
next($t);
echo current($t).'<br />';

echo key($t).'<br />';


//向前移動(dòng)一下
prev($t);
echo current($t).'<br />';
echo key($t).'<br />';


//移到末尾
end($t);
echo current($t).'<br />';
echo key($t).'<br />';

//移至開(kāi)始處
reset($t);
echo current($t).'<br />';

echo key($t).'<br />';


//銷毀數(shù)組
unset($t);
var_dump($t);
?>


Continuing Learning
||
<?php $t=array( '我們', 'yy'=>'永遠(yuǎn)', 'dbg'=>'需要不斷奮進(jìn)', 'djn'=>'才能開(kāi)創(chuàng)未來(lái)' ); //讀取數(shù)組的值 echo current($t).'<br />'; //讀取數(shù)組的鍵 echo key($t).'<br />'; //向后移動(dòng)一下 next($t); //再讀值和鍵 echo current($t).'<br />'; echo key($t).'<br />'; //向后移動(dòng)一下 next($t); echo current($t).'<br />'; echo key($t).'<br />'; //向前移動(dòng)一下 prev($t); echo current($t).'<br />'; echo key($t).'<br />'; //移到末尾 end($t); echo current($t).'<br />'; echo key($t).'<br />'; //移至開(kāi)始處 reset($t); echo current($t).'<br />'; echo key($t).'<br />'; //銷毀數(shù)組 unset($t); var_dump($t); ?>
submitReset Code

FunctionFunction

<abbr id="gfgox"><tt id="gfgox"></tt></abbr>