我正在尝试弄清楚为我提供的功能是如何工作的——或者更确切地说,它是如何工作的。有问题的区域包括像这样的数组符号:
$small[$end[$i]{0}]
我认为这个想法是将“0”附加到$end[$i]
的值,并将其用于$small 的索引。但它在 PHP5.3 中不起作用。这是一种已弃用的语法吗?它是否在尝试按照我的想法行事?
最佳答案
它从 $end[$i]
字符串中获取第一个字符,然后使用该字符作为数组键访问 $small
数组。
编辑:
Since
$foo=200; $foo[0] != 2;//==''
, what do you recommend for getting the leftmost digit when the magnitude of the number is unknown?
最简单的方法是在 PHP 中使用 substr($foo, 0, 1)
。
如果您使用的是强类型语言,我有一些指标您可能有兴趣阅读我的另一个答案:How can you get the first digit in an int (C#)?
关于php - 奇怪的数组语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2699098/