Answers for "array map count php"

PHP
3

php count array elements with specific key

$cnt = count(array_filter($array,function($element) {
  return $element['your_key']=='foo';
}));
Posted by: Guest on July-13-2020
1

array map php

The array_map() function sends each value of an array to a user-made function, and returns an array with new values, given by the user-made function.

Tip: You can assign one array to the function, or as many as you like.

Syntax
array_map(functionname, array1, array2, array3, ...)
  
Example
Send each value of an array to a function, multiply each value by itself, and return an array with the new values:

<?php
function myfunction($val)
{
  return($val*$val);
}

$a=array(1,2,3,4,5);
print_r(array_map("myfunction",$a));
?>
Posted by: Guest on April-01-2020

Browse Popular Code Answers by Language