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?
Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To create an array, define the data type (like int ) and specify the name of the array followed by square brackets [].
Syntax to initialize an array:-int numbers[] = {2, 3, 4, 5, 6}; int numbers[] = {2, 3, 4, 5, 6}; int numbers[] = {2, 3, 4, 5, 6}; In case, if you don't specify the size of the array during initialization then the compiler will know it automatically. numbers[0] = 2.
Array declaration syntax is very simple. The syntax is the same as for a normal variable declaration except the variable name should be followed by subscripts to specify the size of each dimension of the array. The general form for an array declaration would be: VariableType varName[dim1, dim2, ...
A typical declaration for an array in C++ is: type name [elements]; where type is a valid type (such as int, float ...), name is a valid identifier and the elements field (which is always enclosed in square brackets [] ), specifies the size of the array.
It's getting the first character from the $end[$i]
string and then accessing the $small
array using that character as the array key.
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#)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With