Core Function UBound
From Sputnik Wiki
(Difference between revisions)
(→Example) |
|||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | UBound( <array/binary-array | + | UBound( <array/binary-array> ) |
</pre> | </pre> | ||
Line 16: | Line 16: | ||
The binary variable to use. | The binary variable to use. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Return Value === | === Return Value === | ||
Line 36: | Line 27: | ||
Remember that the value returned by UBound is one greater than the index of an array's last element! | Remember that the value returned by UBound is one greater than the index of an array's last element! | ||
− | + | In Sputnik an array does not necessary start at index 0 and move upwards infact an array can start at any number and jump all over place this all depends where the user has placed items into the array. | |
− | + | If the user uses push() then all items in array will be correct order. | |
=== Example === | === Example === |
Revision as of 12:42, 28 January 2013
UBound( <array/binary-array> )
Contents |
Description
Returns the size of array (How many elements it currently has stored).
Parameters
array/binary-array
The array to use.
OR
The binary variable to use.
Return Value
Success - Returns the current size of the array/binary-array.
Failure - Returns an empty array.
Remarks
Remember that the value returned by UBound is one greater than the index of an array's last element!
In Sputnik an array does not necessary start at index 0 and move upwards infact an array can start at any number and jump all over place this all depends where the user has placed items into the array.
If the user uses push() then all items in array will be correct order.
Example
$arrayOLD = array ( 10..15, 24..30 ); $i = 0; Foreach( $arrayOLD as $j ) { println("Element ($i) is: " . $j); $i++; } println("Size is: " . UBound($arrayOLD) ); // Prints 13
Heres an example of getting the size of binary data :
$binary = Pack("z0", "Hello World!"); // Yes you can get the size of the binary byte array by using UBound just like with arrays println("The binary size is: " . UBound($binary) ); Foreach ( $binary as $i ) { println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); }