yuptyy
V2EX  ›  PHP

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

  •  
  •   yuptyy · Mar 31, 2015 · 3212 views
    This topic created in 4251 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
    zeayes
    Mar 31, 2015❤️1
    1
    这个是递归
    yuptyy
    yuptyy
    OP
    Mar 31, 2015
    2
    @zeayes 可以实现具体的代码么
    zeayes
    zeayes
    Mar 31, 2015❤️1
    3
    # -*- coding: utf-8 -*-

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

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

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