tags:

views:

94

answers:

1
+6  Q: 

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?

+9  A: 

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: http://stackoverflow.com/questions/701322/how-can-you-get-the-first-digit-in-an-int-c/701621#701621

John Rasch
thanks for correcting my understanding of what it's trying to do. B
dnagirl