
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to get the length of longest string in a PHP array
The array_map function can be used to get the length and the max function can be used to get the length of the longest string.
Below is a code sample for the same −
$max_len = max(array_map('strlen', $array));
Example
$array = array("a", "Ab", "abcd", "abcdfegh", "achn"); $max_len = max(array_map('strlen', $array)); echo $max_len;
Output
This will produce the following output −
8
- Related Articles
- How to get the longest VarChar length in MySQL?
- PHP – Get the string length using mb_strlen()
- How to get the length of a string in Python?
- How to get the length of a string in JavaScript?
- How to get the Length of a String in Java?
- Get the longest and shortest string in an array JavaScript
- Length of longest string chain in JavaScript
- How to get the length of a string in bytes in JavaScript?
- Finding the length of longest vowel substring in a string using JavaScript
- Find longest length number in a string in C++
- Program to find length of longest repeating substring in a string in Python
- Find the Length of the Longest possible palindrome string JavaScript
- PHP – How to get the selected part of a string using mb_substr()?
- How to get the first element of an array in PHP?
- Program to find length longest prefix sequence of a word array in Python

Advertisements