How to Get the length of an array in PHP?

in array length in php, You can easy use the main Two types of the ways first is a PHP count() as well as sizeof() method to get the number of elements as well as data values in an array. The count() and sizeof() method results data returns 0 for a variable that has been initialized with an empty array, so it may also results return 0 for a php variable that is not any set.

Read Also:  Learn Laravel (Best Laravel Tutorials for Beginners)

array length in php

  • using count() function
  • using sizeof() function

php count array lengths elements with specific value

PHP count() function

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example of Counting an Array Values in PHP</title>
</head>
<body>
<h2>array length in php</h2>
<?php
$movies = array("tamilrokers", "jiorokers", "bolly4u", "mymaths", "litanswers", "khatrimaza", "pakainfo");
 
// display array size
echo 'Your Total number of movies in the $movies array is - ' . count($movies);
echo "<br>";
echo 'Your Total number of movies in the $movies array is - ' . sizeof($movies);
?>

</body>
</html>

PHP Array Lengths Size Count Tutorial With Example

Read Also:  PHP Laravel 5.6 Dynamically Add Active class

PHP sizeof() function

<!DOCTYPE html>
<html>
<body>

<?php
$movies=array
    (
    "tamilrokers"=>array
    (
    "TAMIL",
    "HINDI"
    ),
    "JIO"=>array
    (
    "PAKA",
    "INFO"
    ),
    "BOLYY4U"=>array
    (
    "okhatrimaja"
    )
    );

echo "Normal count: " . sizeof($movies)."<br>";
echo "Recursive count: " . sizeof($movies,1);
?>

</body>
</html>

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about array lengths in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  How to count files in a directory using PHP Laravel?

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Simple PHP Laravel Pagination script
  2. Read Also:  Laravel 6 Advanced Where Clauses Tutorial With Example
  3. Read Also:  jQuery Ajax Call to Laravel Script with JSON Return
  4. Read Also:  pagination code in php with next and previous demo
  5. Read Also:  sql having clause Examples
  6. Read Also:  AngularJS push item to 0 index or first of $scope object
  7. Read Also:  PHP nested While Loops and Multiple Conditions
  8. Read Also:  Add prefix in each key of PHP Array
  9. Read Also:  Laravel Dynamic Active Class Menu
  10. Read Also:  Jquery Count Child Elements with class
CLOSEX