note 121939 added to function.array-count-values
| From: | sergolucky96 at gmail dot com | Date: | Wed, 29 Nov 2017 13:52:06 +0000 |
| Subject: | note 121939 added to function.array-count-values | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209247@lists.php.net to get a copy of this message | ||
Simple way to find number of items with specific values in multidimensional array:
<?php
$list = [
['id' => 1, 'userId' => 5],
['id' => 2, 'userId' => 5],
['id' => 3, 'userId' => 6],
];
$userId = 5;
echo array_count_values(array_column($list, 'userId'))[$userId]; // outputs: 2
?>
----
Server IP: 208.43.231.9
Probable Submitter: 91.237.240.4
----
Manual Page -- http://php.net/manual/en/function.array-count-values.php
Edit -- https://master.php.net/note/edit/121939
Del: integrated -- https://master.php.net/note/delete/121939/integrated
Del: useless -- https://master.php.net/note/delete/121939/useless
Del: bad code -- https://master.php.net/note/delete/121939/bad+code
Del: spam -- https://master.php.net/note/delete/121939/spam
Del: non-english -- https://master.php.net/note/delete/121939/non-english
Del: in docs -- https://master.php.net/note/delete/121939/in+docs
Del: other reasons-- https://master.php.net/note/delete/121939
Reject -- https://master.php.net/note/reject/121939
Search -- https://master.php.net/manage/user-notes.php