Jump to content


Find Position in Array and Match to Other Array

  • Please log in to reply
1 reply to this topic

#1 casbboy

  • Members
  • PipPip
  • Member
  • 15 posts

Posted 13 September 2006 - 10:32 PM

Here is what I have:

First, I set up two arrays to be used later (from a mysql query):

while($alinks = mysql_fetch_array($listlinks)) {
$clinks[] = $alinks['link'];
$cid[] = $alinks['article_id'];

Now I check to see if a new set of links matches any in the $clinks array:

$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;

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?

Again, thanks for all the help I recieve

#2 Kris

  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 14 September 2006 - 06:44 AM

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)).

//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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users