Jump to content

Help with adding array value


everisk

Recommended Posts

Hi,

 

I need to find if 2 array contains  same value, if so then add their count values. For example, I have the below array. I have to add

'count' of array 0 and array 1 because the 'url' is the same (open). I have to also add 'count' of array 2 and array 3 because the 'url' is the same. Thank you in advance!

 

Array
(
    [0] => Array
        (
            [lid] => 1567
            [url] => open
            [count] => 736
        )

    [1] => Array
        (
            [lid] => 1573
            [url] => open
            [count] => 265
        )

    [2] => Array
        (
            [lid] => 1568
            [url] => http://my.sony.co.th/newsletter/issue/SonyCenter_promotion/index.html
            [count] => 186
        )

    [3] => Array
        (
            [lid] => 1575
            [url] => http://my.sony.co.th/newsletter/issue/SonyCenter_promotion/index.html
            [count] => 73
        )
)

 

My code that populate the array

 

$i=0;
while($row = mysql_fetch_array($table)) {
//get URL name
$sql2 = "select * from all_links where id=$row[lid]";
$tab2 = mysql_query($sql2) or die("Cannot get URL");
$url = mysql_fetch_array($tab2);

$t_link[$i]['lid'] = $row['lid'];
$t_link[$i]['url'] = $url['link'];
$t_link[$i]['count'] = $row['clid'];

$i++;
} 

Link to comment
https://forums.phpfreaks.com/topic/61490-help-with-adding-array-value/
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.