Extract the number of certain PHP elements
-
<?php foreach ($orders as $order) { ?> <?php echo $order['order_type']; ?> <?php } ?>
Delete: 2 2 2 2 2 2 2 3 2 2
Explain how to remove and calculate the ring of certain elements in the mass
We need to look at this:
Elements with number 2: 7
Elements with number 3: 3
-
As an option, can be this way ( https://www.php.net/manual/ru/function.array-column.php + https://www.php.net/manual/ru/function.array-count-values.php
foreach(array_count_values(array_column($orders, 'order_type')) as $k => $v) { echo 'Элементы с номером ', $k, ': ', $v, PHP_EOL; }