everisk Posted July 9, 2007 Share Posted July 9, 2007 I have array that looks like below. I want to add the count of the array if the URL is the same. For example, array[4] is the same as array[6] then array[count][4] + array[count][6]. Any help would be greatly appreciated. I am not so good with array . Thanks! Array ( [url] => Array ( [0] => open [1] => open [2] => open [3] => open [4] => http://my.sony.co.th/newsletter/issue/issue-MySony058June6/index.html [5] => http://www.sony.co.th/DSLR/a100/ [6] => http://my.sony.co.th/newsletter/issue/issue-MySony058June6/index.html [7] => http://www.sony.co.th/DSLR/a100/ ) [count] => Array ( [0] => 3315 [1] => 2247 [2] => 516 [3] => 293 [4] => 274 [5] => 204 [6] => 193 [7] => 178 ) ) This is my code $t_link = array("url"=>array(""), "count"=>array("")); $i=0; $sql = "SELECT count(lid) as clid, lid ,nl,times FROM linksd a where n=146||n=147||n=137||n=138 group by lid order by clid DESC"; $table = mysql_query($sql) or die("Cannot get count"); while($row = mysql_fetch_array($table)) { //get URL name $sql2 = "select * from links where id=$row[lid]"; $tab2 = mysql_query($sql2) or die("Cannot get URL"); $url = mysql_fetch_array($tab2); $t_link["url"][$i] = $url['link']; $t_link["count"][$i] = $row['clid']; $i++; } echo "<pre>"; print_r($t_link); die; Link to comment https://forums.phpfreaks.com/topic/59046-add-2-array-values/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.