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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.