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
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
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.
Here is the sample code.
///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);
i m confused about one thing ... plz help me out
i am using an array for displaying the records in a loop. but i need to count an array printing the same value of records (means how many times the same value is being printed by the array)...
is there any particular way to do so ?
You can use array_count_values function for this. There is a link to this tutorial inside Further readings section.
can i use this function i my tpl files
<input type='text' value='sizeof($MLSColl)' id='t1'>
If any PHP code is getting executed inside tpl file then this will also work.
count array size of array of array ??
many thanx,i used this site,thanx very much,there r many many thing i didnt know,but i learnt a lot from here.
what id reason of count function add 0 after print length of array?
b=50 ---- 0 is why ?
tell me answer
how can i get only key of associative array not their value?
If you try to print the value of $b it will be 5 only. Not 50.
You can get only keys by using array_keys() function.