- Chr ($a)
- sizeof ($a)
- Len ($a)
- count ($a)
- strlen ($a)
Instance
Returns a character from a different ASCII value:
Hexadecimal value?>
Running an instance
Definition and usage
The CHR () function returns characters from the specified ASCII value.
The ASCII value can be specified as a decimal value, an octal value, or a hexadecimal value. The octal value is defined with a front 0, and the hexadecimal value is defined with a front 0x.
Grammar
Chr (ASCII)
Parameters |
Description |
Ascii |
Necessary. ASCII value. |
Technical details
return value: |
Returns the specified character. |
PHP version: |
4 + |
More examples of examples 1
Use the octal value 046来 to add the ASCII character:&.
<?PHP$STR = Chr (046); Echo ("You $str me forever!");? >
Running an instance
Example 2
Use decimal values 43 and 61来 to add ASCII characters: + and =.
<?PHP$STR = CHR; $str 2 = CHR; Echo ("2 $str 2 $str 2 4");? >
Running an instance
Instance
Returns the number of elements in the array:
<?php$cars=array ("Volvo", "BMW", "Toyota"); echo sizeof($cars)
;? >
Running an instance
Definition and usage
The sizeof () function calculates the number of cells in an array or the number of properties in an object.
The sizeof () function is the alias of the Count () function.
Note: When the variable is not set, or the variable contains an empty array, the function returns 0. You can use the Isset () variable to test whether a variable is set.
Grammar
sizeof (array,mode);
Parameters |
Description |
Array |
Necessary. Specifies the array. |
Mode |
Optional. prescribed mode. Possible values:
- 0-Default. All elements in a multidimensional array are not counted.
- 1-counts the number of elements in the array recursively (computes all elements in the multidimensional array).
|
Technical details
return value: |
Returns the number of elements in the array. |
PHP version: |
4 + |
More examples of examples 1
To recursively calculate the number of elements in an array:
<?php$cars=array (" Volvo" =>array (" XC60", "XC90" ), "BMW" =>array ( " X3", "X5" ), "Toyota" =>array ( "Highlander" ) sizeof($cars)
sizeof($cars,1)
; >
Running an instance
Instance
Returns the number of elements in the array:
count($cars)
;? >
Running an instance
Definition and usage
The count () function returns the number of elements in the array.
Grammar
COUNT (array,mode);
Parameters |
Description |
Array |
Necessary. Specifies the array. |
Mode |
Optional. prescribed mode. Possible values:
- 0-Default. Do not count all elements in a multidimensional array
- 1-counts the number of elements in the array recursively (computes all elements in a multidimensional array)
|
Description
The count () function calculates the number of cells in an array or the number of properties in an object.
For an array, returns the number of its elements, and returns 1 for other values. Returns 0 if the argument is a variable and the variable is not defined.
If mode is set to Count_recursive (or 1), the number of elements in the array in the multidimensional array is recursively computed.
Technical details
return value: |
Returns the number of elements in the array. |
PHP version: |
4 + |
Update log: |
The mode parameter is added in PHP 4.2. |
More examples of examples 1
To count recursively on an array:
<?php$cars=array (" Volvo" =>array (" XC60", "XC90" ), "BMW" =>array ( " X3", "X5" ), "Toyota" =>array ( "Highlander" ) count($cars)."<br>"
count($cars,1)
; >
Running an instance
PHP strlen Gets the string length strlen
(PHP 4, PHP 5)
strlen- Get string length
Description
int strlen ( string $string )
Returns the length of the given string.
Parameters
-
string
-
A string that requires a length calculation .
return value
Success returns the length of the string, or 0 if string is empty.
Example
Example #1 strlen () Example
<?php
$str = ‘abcdef‘;
echo strlen($str); // 6
$str = ‘ ab cd ‘;
echo strlen($str); // 7
?>
See
- COUNT ()-Calculates the number of cells in an array or the number of attributes in an object
- Mb_strlen ()-Get string length
- Answer E
[Single topic] Which of the following statements can return the character count of a string variable $ A?