User Tools

Site Tools


uphp:functions:sizeof

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

uphp:functions:sizeof [2017/04/12 13:02]
jeff
uphp:functions:sizeof [2021/09/13 05:57]
Line 1: Line 1:
-======sizeof====== 
- 
-<badge>WMPRO, WMMINI FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge> 
- 
-Return the number of elements in an <html><b><span style="color:green">array<span style="color:black"></b></html> 
- 
-====Description==== 
- 
-<well size="sm"> 
-<html> 
-<span style="font-size:125%;color:green">int 
-<span style="color:black"> 
-</html> 
-[[sizeof]] ( 
-<html> 
-<span style="color:green">array 
-<span style="color:blue">$array 
-<span style="color:black">) 
-</html> 
-</well> 
- 
-====Parameter==== 
- 
-<html><b><span style="color:blue">$array<span style="color:black"></b>:  Any <b><span style="color:green">array<span style="color:black"></b> object</html> 
- 
-====Return Value==== 
- 
-<html><b><span style="color:green">Integer<span style="color:black"></b> number of elements in the <b><span style="color:green">array<span style="color:black"></b></html> 
- 
-====Examples==== 
- 
-<code php> 
-<? 
- 
-  $array1[0]=1; 
-  $array1[1]=3; 
-  $array1[2]=5; 
-  print(sizeof($array1)); // output 3 
-   
-  $array2[0]=7; 
-  $array2[5]=9; 
-  $array2[10]=11; 
-  print(sizeof($array2)); // output 3 
-   
-  $array3=array();        // blank array 
-  print(sizeof($array3)); // output 0 
-   
-  $array3=indexed_array(1,100); // indexed array of bytes 
-  print(sizeof($array3));       // output 100 
-   
-  $array4=array(1,2,3,4);                 // array of integers 
-  $array5=array("one",2,3.33333,$array4); // mixed multidimensional array 
-  print(sizeof($array5));                 // output 4 
- 
-  $s="string";       // not an array 
-  print(sizeof($s)); // output 0 
-   
-  print(sizeof($undefined)); // output 0 
-     
-?> 
-</code> 
- 
-====Notes==== 
- 
-Array indexes are 0-based, but the count of the number of elements in an array is 1-based. Furthermore, [[sizeof()]] may have no relationship at all to the index numbers, which can vary depending on how the array is defined (see the second example above where the 3rd element of $array2 is index number 10). 
- 
-This is the uPHP version of the PHP function ''sizeof()'' which is an alias of the function ''count()''. 
- 
-Multidimensional arrays are not counted recursively, i.e., each element which is an array adds '1' to the total count of elements (see above example). 
- 
-As can be seen from the examples, uPHP always returns 0 for objects which are not arrays (mainline PHP will return 1 in some cases). If you are not certain the object is an <html><b><span style="color:green">array<span style="color:black"></b></html> it is best to first use function [[is_array()]]. 
- 
-====See Also==== 
- 
-[[array()]] - Create an <html><b><span style="color:green">array<span style="color:black"></b></html>, with optional values 
- 
-[[array_key()]] - Return the key for an <html><b><span style="color:green">array<span style="color:black"></b></html> index 
- 
-[[array_keys()]] - Return keys for an <html><b><span style="color:green">array<span style="color:black"></b></html> that has key/value pairs 
- 
-[[explode()]] - <html>Turn a <b><span style="color:green">string<span style="color:black"></b> into an <b><span style="color:green">array<span style="color:black"></b></html> 
- 
-[[implode()]] - <html>Turn an <b><span style="color:green">array<span style="color:black"></b> into a <b><span style="color:green">string<span style="color:black"></b></html> 
- 
-[[indexed_array()]] - Create an <html><b><span style="color:green">array<span style="color:black"></b></html> of a specific type and size 
- 
-[[is_array()]] - Check if a variable is an <html><b><span style="color:green">array<span style="color:black"></b></html> 
- 
-[[json_encode()]] - <html>JSON encode an <b><span style="color:green">array<span style="color:black"></b> into a <b><span style="color:green">string<span style="color:black"></b>, with optional method</html> 
- 
-[[print_r()]] - Dump the contents of an <html><b><span style="color:green">array<span style="color:black"></b></html> to the current output 
- 
-[[uphp:variables|uPHP Variable Types and Limits]] 
  
uphp/functions/sizeof.txt · Last modified: 2021/09/13 05:57 (external edit)