简体   繁体   中英

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;//=='' $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#)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM