Core Function Count
m (1 revision) |
|||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | Count( <array/binary-array> ) | + | Count( <array/binary-array/class> ) |
</pre> | </pre> | ||
Line 16: | Line 16: | ||
The binary variable to use. | The binary variable to use. | ||
+ | |||
+ | OR | ||
+ | |||
+ | A class to use that extends the Countable class. | ||
=== Return Value === | === Return Value === | ||
− | Success - Returns the total amount of elements in the array/binary-array. | + | Success - Returns the total amount of elements in the array/binary-array or what the count property returned from the class. |
Failure - Returns null. | Failure - Returns null. | ||
Line 58: | Line 62: | ||
println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); | println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); | ||
} | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Using a class with extended Countable so that the property named count gets used to return a value for count() example. | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | Class Testy extends Countable | ||
+ | { | ||
+ | override my $Count { get { return 700; } } | ||
+ | } | ||
+ | $a = new Testy(); | ||
+ | say count($a); | ||
+ | // PRINTS | ||
+ | // 700 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 18:37, 21 September 2015
Count( <array/binary-array/class> )
Contents |
Description
Returns the total amount of elements in an array.
Parameters
array/binary-array
The array to use.
OR
The binary variable to use.
OR
A class to use that extends the Countable class.
Return Value
Success - Returns the total amount of elements in the array/binary-array or what the count property returned from the class.
Failure - Returns null.
Remarks
Remember that the value returned by Count 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.
This also returns how many characters are in a string.
Example
$arrayOLD = array ( 10..15, 24..30 ); $i = 0; Foreach( $arrayOLD as $j ) { println("Element ($i) is: " . $j); $i++; } println("Size is: " . Count($arrayOLD) ); // Prints 13
Heres an example of getting the size of binary data :
$binary = Pack("A*", "Hello World!"); // Yes you can get the size of the binary byte array by using Count just like with arrays println("The binary size is: " . Count($binary) ); Foreach ( $binary as $i ) { println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); }
Using a class with extended Countable so that the property named count gets used to return a value for count() example.
Class Testy extends Countable { override my $Count { get { return 700; } } } $a = new Testy(); say count($a); // PRINTS // 700