1

I'm working with the following code kindly supplied in an answer here but it generates the following errors

Warning: array_map() [function.array-map]: Argument #2 should be an array in [path/to] on [Line #]

and

'Warning: Wrong parameter count for array_intersect() in [path/to] on [line #]'

Googleing the errors has produced no useful ideas - any help appreciated.

<?php
$types = array('.pdf', '.doc', '.xls');
if(0 < count(array_intersect(array_map('strtolower', $filename, $types)))) {
   echo 'One';
} else {
   echo 'Two';
}
?>

//update

<?php
$filename = array(get_post_meta(get_the_ID(), 'mjwlink-url'));
$types = array('.pdf', '.doc', '.xls');
if(0 < count(array_intersect(array_map('strtolower', $filename), $types))) {
   echo 'One';
} else {
   echo 'Two';
}

?>

Community
  • 1
  • 1
toomanyairmiles
  • 6,465
  • 8
  • 43
  • 71

2 Answers2

2

strtolower takes exactly one argument, while array_map with three arguments ($fun, $arr1, $arr2) takes function fun, which must take two arguments itself: fun(arg1, arg2). Look at Example #3 in array_maps docs page.

PS $filename variable is not initialized in your code?


EDIT: You probably want array_intersect(array_map('strtolower', $filename), $types) instead (you put bracket in wrong place)...

Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112
0

For array_map the second argument needs to be an array, so I guess you should be passing $types there and not $filename.

Also, you need to pass at least two arrays into array_intersect. You're actually only passing one there.

Darragh Enright
  • 13,676
  • 7
  • 41
  • 48