【发布时间】:2013-07-05 16:22:03
【问题描述】:
我看到here提出了这个特殊问题
我的问题略有不同。
假设我有一个随机整数(可以是任何数字)
像这样:$rank=123456
同样可以是$rank=2876545672
我想要做的是将整数动态拆分成一个数组,并给每个值一个类。
所以它会在示例中抓取:123456 第一个数字并分配一个类似 digit-<?=$num['id'] 的变量
所以我可以生成类似的东西:
<span class="digit-1">1</span>
<span class="digit-2">2</span>
<span class="digit-3">3</span>
<span class="digit-4">4</span>
<span class="digit-5">5</span>
<span class="digit-6">6</span>
这可能吗?如果可以,有什么想法可以实现吗?由于 tha bove ( spans ) 需要动态操作,以便根据生成的任何数字创建它们。
让我发疯想弄清楚。
【问题讨论】:
-
使用
str_split。$vals = str_split($rank);:-) -
看到这个问题stackoverflow.com/questions/4868896/how-do-i-explode-an-integer 并应用你的html样板
标签: php