V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
thankyourtender
V2EX  ›  PHP

获取第一个值 最好不要用 array[0] 而是 current (array)

  •  
  •   thankyourtender · 2014-07-30 16:03:23 +08:00 · 3282 次点击
    这是一个创建于 3559 天前的主题,其中的信息可能已经有所发展或是发生改变。
    12 条回复    2014-09-06 01:09:16 +08:00
    Keyes
        1
    Keyes  
       2014-07-30 16:04:09 +08:00 via iPhone
    为什么呢?
    teavoid
        2
    teavoid  
       2014-07-30 16:08:03 +08:00
    好没头没脑的感觉
    raincious
        3
    raincious  
       2014-07-30 16:08:22 +08:00
    @Keyes 因为array[0]不一定有。

    但为什么是current?执行了next之后怎么办?
    lyragosa
        4
    lyragosa  
       2014-07-30 16:08:39 +08:00
    不明所以。
    imn1
        5
    imn1  
       2014-07-30 16:11:24 +08:00
    如果要多次获取呢?
    wy315700
        6
    wy315700  
       2014-07-30 16:12:41 +08:00
    @imn1 多次获取用foreach啊
    imn1
        7
    imn1  
       2014-07-30 16:15:36 +08:00
    @wy315700 我说的是多次获取第一个值,不是顺序获取
    raincious
        8
    raincious  
       2014-07-30 16:16:20 +08:00
    @imn1

    array_splice。其实这个可以解决包括楼主的问题。所以不明白,非得current?微优化?

    http://stackoverflow.com/questions/2473989/list-of-big-o-for-php-functions
    thankyourtender
        9
    thankyourtender  
    OP
       2014-07-30 16:22:19 +08:00
    呵呵
    wtbhk
        10
    wtbhk  
       2014-07-30 16:30:59 +08:00
    已Block
    lzsadam
        11
    lzsadam  
       2014-07-30 16:57:50 +08:00
    围观
    shanqiu
        12
    shanqiu  
       2014-09-06 01:09:16 +08:00
    拿的时候 if isset() 判断一下再用吧。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2028 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 16:13 · PVG 00:13 · LAX 09:13 · JFK 12:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.