yuptyy
V2EX  ›  PHP

如何迭代实现数组的不断插入

  •  
  •   yuptyy · Mar 31, 2015 · 2974 views
    This topic created in 4110 days ago, the information mentioned may be changed or developed.

    $str= 'aple'
    最后的输出效果如下

    a => [
    p => [
    l => [
    e => [
    ]
    ]
    ]
    ]

    7 replies    2015-03-31 16:15:41 +08:00
    zeayes
        1
    zeayes  
       Mar 31, 2015   ❤️ 1
    这个是递归
    yuptyy
        2
    yuptyy  
    OP
       Mar 31, 2015
    @zeayes 可以实现具体的代码么
    zeayes
        3
    zeayes  
       Mar 31, 2015   ❤️ 1
    # -*- coding: utf-8 -*-

    def insert(input_string):
    if input_string:
    print input_string[0] + ' => ['
    insert(input_string[1:])
    print ']'

    insert('aple')
    zhujinliang
        4
    zhujinliang  
       Mar 31, 2015   ❤️ 1
    https://gist.github.com/yurinacn/65afff8c372f8a9e722d

    php对于数组处理过于诡异。。。
    yuptyy
        5
    yuptyy  
    OP
       Mar 31, 2015
    @zhujinliang 妹子18岁 我好汗颜
    hahasong
        6
    hahasong  
       Mar 31, 2015
    @zhujinliang 妹子175 我好汗颜
    efi
        7
    efi  
       Mar 31, 2015 via Android
    v3rc居然有妹子 我好汗颜
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1132 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 23:12 · PVG 07:12 · LAX 16:12 · JFK 19:12
    ♥ Do have faith in what you're doing.