• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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.

 1 $queue = array('a', 'b', 'c');
 2 array_shift($queue);
 3 wb($queue);
 4 $queue = array('a', 'b', 'c','D'=>'dd',array('shift','shift_1'));
 5 array_shift($queue);
 6 wb($queue);
 7 echo '----------------------------<br>';
 8 $queue = array('a', 'b', 'c','D'=>'dd',array('shift','shift_1'));
 9 w($queue[count($queue)-2]);
10 w(current($queue));
11 w(next($queue));
12 w(next($queue));
13 array_shift($queue);
14 wb($queue);
15 
16 function wb($w){
17     w($w);
18     if (is_array($w)) {
19         w(current($w));
20     } else {
21         w('! is_array(var)');
22     }
23 }
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)

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
php多维数组发布时间:2022-07-10
下一篇:
PHP通用函数 - 日期生成时间轴发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap