php - Using strlen() with arrays instead of strings -


i want use strlen() compare length of 2 arrays. if length of 1 array greater other, something.

unfortunately, noticed strlen() works strings? how can make work arrays?

my code:

    $array1 = array(         'hello world',         'hello world',         'hello world',         'hello world',         'hello world'     );      $array2 = array(         'hello world',         'hello world'     );   if (strlen($array1) > strlen($array2)) {      echo 'it works fool!';  } 

how can make work arrays?

php manual strlen():

strlen() returns null when executed on arrays, , e_warning level error emitted.

you can't really.

is there reason why "want" this?
there function achieve want - count():

count — count elements in array, or in object

if (strlen($array1) > strlen($array2))   {     echo 'it works fool!';   } 

don't try work php functions suit needs in scenarios not designed for.
when there (almost likely) function suits needs.

future changes make "hack" no longer work, , using correct function means benefit php ensuring accuracy, stability, speed, etc etc.

hacking around causes headaches, if not now, in future.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -