casbboy Posted September 13, 2006 Share Posted September 13, 2006 Here is what I have:First, I set up two arrays to be used later (from a mysql query):[code=php:0]while($alinks = mysql_fetch_array($listlinks)) {$clinks[] = $alinks['link'];$cid[] = $alinks['article_id'];}[/code]Now I check to see if a new set of links matches any in the $clinks array:[code=php:0]$nc = 0;$pos = 0;foreach($info[items] as $in) { if(in_array($info[items][$nc][link], $clinks)) { $pos = strpos($info[items][$nc][link], $clinks); $abar = '<a href="/article/'. $cid[$pos] .'"><img src="/images/art/indexed.gif" border="0"></a>'; } else { $abar = '<img src="/images/art/notindexed.gif">'; }$nc = $nc + 1;}[/code]If the link already exists, I want the 'article_id' of the matched link to be placed in to the href. Hence I have the $cid array with the $pos variable giving the position with $cid[$pos]. Unfortunately, this isn't working as I had hoped, and only gives the same number for all the links that match.ANy suggestions?ThanksRyan Link to comment https://forums.phpfreaks.com/topic/20669-find-position-in-array-and-match-to-other-array/ Share on other sites More sharing options...
zq29 Posted September 14, 2006 Share Posted September 14, 2006 As far as I'm aware, strpos() doesn't accept an array as an argument (and even if it did, you have them around the wrong way, the arguments are positioned strpos(haystack,needle)).[code]<?php//Try replacing$pos = strpos($info[items][$nc][link], $clinks);//With this$pos = array_search($info['items'][$nc]['link'],$clinks);//Just a tip$nc = $nc + 1;//Can be written like this$nc++;?>[/code] Link to comment https://forums.phpfreaks.com/topic/20669-find-position-in-array-and-match-to-other-array/#findComment-91556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.