-2

Warning: strlen() expects parameter 1 to be string, array given in symfony 4

This is my error.

How to solve this? Please Help.

Birendra Gurung
  • 2,168
  • 2
  • 16
  • 29

2 Answers2

0

The function strlen() is used to retrieve the length of a string. So you should pass a string as a parameter not an array. The error is pretty much self explanatory.

Mohammed Saimon
  • 563
  • 1
  • 5
  • 10
0

Summary and useful :

  • count() : size of the an array

  • strlen() : length of string

Several useful and relevant links:  

Warning: strlen() expects parameter 1 to be string, array given in file... in line

Warning: strlen() expects parameter 1

Warning: strlen() expects parameter 1 to be string, array given

http://php.net/manual/en/function.strlen.php

Calculate the length of the string of elements of a one-dimensional array:  

<?php
$array=array("Hello","How are you","Are you good?","Yeah");
//This is not correct! : strlen($array);
foreach($array as $item)
{
$length=strlen($item);
echo $item." ( $length )\n";
}
?>

Output :

Hello ( 5 )
How are you ( 11 )
Are you good? ( 13 )
Yeah ( 4 )

The strlen($array) will occur a warning.

PHP Warning:  strlen() expects parameter 1 to be string, array given in ... on line ...
Max Base
  • 639
  • 1
  • 7
  • 15