answersLogoWhite

0


Best Answer
To find out how many results there are in a PHP array all you need to do is use the function count() like I have shown you in the example below.


$my_array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

echo count($my_array); // outputs 10

?>
User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you count how many results are in a PHP array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you count the number of elements in an array using PHP?

Using the function "count". <?php $foo = array("John", "Jacob", "Jingleheimer", "Schmidt"); echo count($foo); // <-- outputs the number 4 ?>


How do you find the size of an array in PHP?

To find the size of an array in PHP you can either use the count() function or the sizeof() function as they will produce the same result. <?php $array = array(1, 2, 3, 4, 5, 6, 7); echo count($array); // outputs 7 echo sizeof($array); // outputs 7 ?>


How do you pick a random value from a PHP array?

To pick random results from an array in PHP you will need to use the array_rand() function, you can select the amount of results you wish it too select too. <?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $rand_results = array_rand($array, 3); // will select 3 random results from the array and store in a new array ?>


How do you reverse the results in a PHP array?

To reverse the results in a PHP array is really simple, all you need to do is use the array_reverse() function like shown below: <?php $my_array = array(1, 2, 3); $reverse_me = array_reverse($my_array); // will be stored as 3, 2, 1 now ?>


How do you count the vowels in a string using PHP?

build an array of vowels then do a foreach on the array and then explode the string on the array value and the answer is -1 of the result


How can you mix up the order of values in a PHP array?

To shuffle an array in PHP is easy to do, all you need to use is the shuffle() function like shown below: <?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); shuffle($array); // array results will be randomly shuffled ?>


How do you empty an array in PHP?

To empty an array in PHP you need to use the unset function like shown below: <?php $array = array('hello', 'hi', 'weee'); unset($array); // empty ?>


How do you merge arrays in PHP?

To merge arrays in PHP all you have to do is use the array_merge() function like shown below: <?php $array1 = array("Matt", "Michael", "Justin"); $array2 = array("Janice", "Janet", "Kylie"); $array3 = array_merge($array1, $array2); ?> One thing to remember when merging arrays is you might be creating duplicate results, if you don't want 2 or more of the same result in the array remember to use the function array_unique() to remove the duplicate results from it!


How do you sort array in php without use of sort function?

$arr=array(2,5,4,6,7,8,1); for($i=0;$i<count($arr);$i++) { for($j=$i;$j<count($arr);$j++) { if($arr[$i] > $arr[$j]) { $temp=$arr[$i]; $arr[$i]=$arr[$j]; $arr[$j]=$temp; } } }


How can you create an array of numbers easily in php?

$foo = array(1.41421356, 1.61803399, 2.71828183, 3.14159265);


How do you separate word in array using php?

To separate a sentence into an array of words, you can use PHP's explode() function. If $text is your sentence, then use the following: $result = explode(" ", $text);


What does array map do in php?

The array_map function in PHP loops over each elements of the passed array(s), and runs the given function. It then returns a new array that contains the values returned by each call to the given function.