PHP array length or size count
Array is very flexible and any time we can add element to array or
remove element from an array. So we must know what are the present number of
elements in an array. To know the total length or total element in an array we have to use count
We will first create an array like this
$array = array ("ABC","DEF", "GHI",
Now we will use the count command to know the number of elements in this
This will output 4 as there are four elements inside the array.
You can use sizeof function also to determine the number of values
The above line output will be 5
echo "size of array = ".sizeof($value)."<br>"; // Output = 5
Words Count ( Sample projects using sizeof function)
we can use sizeof function to count number of words present in paragraph. Here are the steps involved.
1. Store the paragraph of text in a string variable
Here is the sample code.
2. Break the variable and create an array by using split function with space as delimiter
3. Count the number of elements present in the array.
The output is 49
///Storing the sample paragraph in a variable /////
$string='This is a sample string used to count the number of words present in a paragraph of data. You can read this sample text by asking user to enter them in a textara or you can directly read the data present in a file by using PHP file commands.';
///Creating the array by using split function ////
///Generating the output ////
echo "Total Number of words = ".sizeof($our_array);
In ASP UBound function is used to get the size of an array
Number of User Comments : 10