开发者

weird array syntax

I'm trying to figure how a function I've been given works -- or rather doesn't work开发者_运维技巧. The problematic areas include array notation like this:

$small[$end[$i]{0}]

I think the idea is to append "0" to the value of $end[$i] and use that for the index of $small. But it doesn't work in PHP5.3. Is this a deprecated syntax and is it trying to do what I think it is?


It's getting the first character from the $end[$i] string and then accessing the $small array using that character as the array key.

Edit:

Since $foo=200; $foo[0] != 2;//=='', what do you recommend for getting the leftmost digit when the magnitude of the number is unknown?

The easiest way is substr($foo, 0, 1) in PHP.

If you're using a strongly typed language, I have some metrics you may be interested in reading from another answer of mine: How can you get the first digit in an int (C#)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜