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


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.

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

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

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.

There are no comments on this page.

New comment
Code previewClose
Feedback 👍
Comments are sent via email to me.