Jump to content

Grouping / counting foreach results


jjfletch

Recommended Posts

The values of a field in my db looks like:

[code]i.php, j.php, d.php?o=113, i.php, g.php, d.php?0=115, ... [/code]

So, the following foreach statement will basically pluck the elements that start with d.php and display them.

[code]
        preg_match_all('|d\.php\?.+?(?=,)|i', $row['longInfo'], $matchIt);

        foreach ($matchIt[0] as $sampX) {

                echo "$sampX<br />";

        }
[/code]

The above foreach statement will generate the following:

[code]
// We'll call this part Main Blob

d.php?o=113
d.php?o=113
d.php?o=113
d.php?o=113
d.php?o=115
d.php?o=115
[/code]


What I actually need to display is:

d.php?o=113 = 4
d.php?o=115 = 2

Can someone show me how to do this? I tried nesting another foreach statement, but keep receiving "Wrong parameter count" errors.


Link to comment
https://forums.phpfreaks.com/topic/6594-grouping-counting-foreach-results/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.