算法提炼是落脚点-php数组-字符串函数

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

array_unshift() prepends passed elements to the front   of the array. Note that the list of elements is   prepended as a whole, so that the prepended elements stay in the same   order.  All numerical array keys will be modified to start counting from   zero while literal keys won't be touched.

<?php
$queue = array('a', 'b', 'c');
array_unshift($queue, 'unshift');
w($queue);
$queue = array('a', 'b', 'c');
array_unshift($queue, array('unshift','unshift_1'));
w($queue);
$queue = array('a', 'b', 'c','D'=>'dd');
array_unshift($queue, 'unshift');
w($queue);
$queue = array('a', 'b', 'c','D'=>'dd',array('unshift','unshift_1'));
array_unshift($queue, array('unshift','unshift_1'));
w($queue);
die();
D:\wamp64\www\w0827pm\study.php:109:
array (size=4)
0 => string 'unshift' (length=7)
1 => string 'a' (length=1)
2 => string 'b' (length=1)
3 => string 'c' (length=1)
D:\wamp64\www\w0827pm\study.php:109:
array (size=4)
0 =>
array (size=2)
0 => string 'unshift' (length=7)
1 => string 'unshift_1' (length=9)
1 => string 'a' (length=1)
2 => string 'b' (length=1)
3 => string 'c' (length=1)
D:\wamp64\www\w0827pm\study.php:109:
array (size=5)
0 => string 'unshift' (length=7)
1 => string 'a' (length=1)
2 => string 'b' (length=1)
3 => string 'c' (length=1)
'D' => string 'dd' (length=2)
D:\wamp64\www\w0827pm\study.php:109:
array (size=6)
0 =>
array (size=2)
0 => string 'unshift' (length=7)
1 => string 'unshift_1' (length=9)
1 => string 'a' (length=1)
2 => string 'b' (length=1)
3 => string 'c' (length=1)
'D' => string 'dd' (length=2)
4 =>
array (size=2)
0 => string 'unshift' (length=7)
1 => string 'unshift_1' (length=9)

mixed array_shift    ( array &$array   )

array_shift() shifts the first value of the    array off and returns it, shortening the    array by one element and moving everything   down. All numerical array keys will be modified to start counting from zero   while literal keys won't be touched.

 $queue = array('a', 'b', 'c');
array_shift($queue);
wb($queue);
$queue = array('a', 'b', 'c','D'=>'dd',array('shift','shift_1'));
array_shift($queue);
wb($queue);
echo '----------------------------<br>';
$queue = array('a', 'b', 'c','D'=>'dd',array('shift','shift_1'));
w($queue[count($queue)-2]);
w(current($queue));
w(next($queue));
w(next($queue));
array_shift($queue);
wb($queue); function wb($w){
w($w);
if (is_array($w)) {
w(current($w));
} else {
w('! is_array(var)');
}
}
D:\wamp64\www\w0827pm\study.php:133:
array (size=2)
0 => string 'b' (length=1)
1 => string 'c' (length=1)
D:\wamp64\www\w0827pm\study.php:133:string 'b' (length=1)
D:\wamp64\www\w0827pm\study.php:133:
array (size=4)
0 => string 'b' (length=1)
1 => string 'c' (length=1)
'D' => string 'dd' (length=2)
2 =>
array (size=2)
0 => string 'shift' (length=5)
1 => string 'shift_1' (length=7)
D:\wamp64\www\w0827pm\study.php:133:string 'b' (length=1)
----------------------------
D:\wamp64\www\w0827pm\study.php:133:
array (size=2)
0 => string 'shift' (length=5)
1 => string 'shift_1' (length=7)
D:\wamp64\www\w0827pm\study.php:133:string 'a' (length=1)
D:\wamp64\www\w0827pm\study.php:133:string 'b' (length=1)
D:\wamp64\www\w0827pm\study.php:133:string 'c' (length=1)
D:\wamp64\www\w0827pm\study.php:133:
array (size=4)
0 => string 'b' (length=1)
1 => string 'c' (length=1)
'D' => string 'dd' (length=2)
2 =>
array (size=2)
0 => string 'shift' (length=5)
1 => string 'shift_1' (length=7)
D:\wamp64\www\w0827pm\study.php:133:string 'b' (length=1)
上一篇:opencv如何载入内存中的图像文件


下一篇:BZOJ1047: [HAOI2007]理想的正方形 [单调队列]