To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Official ZPE/YASS documentationlist_count_if

list_count_if (list l, function comparator_fn) ⇒ number

Sequentially visits each item in the list and compares it with a comparator function. If the function returns true, then the counter is increased.

First available: Version 1.8.3

Notes

This built-in function is fast and powerful. Using the comparator function you can specify your own criteria for what you are looking for but you can also process the data as it comes through.

YASS
$l = [10, 11, 12, 31, 32, 33]
$small = []

$count = list_count_if($l, function ($x) {
  if ($x > 20) {
    return true
  } else {
    list_add_element($small, $x)
    return false
  }
})

print($count)
print($small)
Do not forget to return false in the inner function since a function with no return value returns null which is not the same as false and can evaluate to true.
Comments

There are no comments on this page.

New comment
Reply
Provide feedback on this page
Comments are sent via email to me.