By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,730 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,730 IT Pros & Developers. It's quick & easy.

error with strpos

P: 63
Hi, here I am again :-)

I'm trying to compare the contents of two arrays and if there's a match, then I would like to place the contents of that one index of the array into a "new" third array.

Here's the code:
Expand|Select|Wrap|Line Numbers
  1.     $myComboVar = array();
  2.  
  3.     for($someVar=0;$someVar<count($myTempArray);$someVar++)
  4.     {
  5.         for($myNewCounter=0;$myNewCounter<count($myTempArray);$myNewCounter++)
  6.         {
  7.             if(strpos($myTempDirArray[$someVar], eval($myTempArray[$myNewCounter]))
  8.             {
  9.                 $myComboVar[$someVar] = $myTempArray[$myNewCounter];
  10.             }
  11.         }
  12.     }
  13.  
  14.     for($i=0;$i<$count;$i++)
  15.     {
  16.      if($i<$count-1)
  17.      {
  18.        $myComboVar2 .= $myComboVar[$i].", ";
  19.      }
  20.      else
  21.      {
  22.        $myComboVar2 .= $myComboVar[$i];
  23.      }
  24.     }
  25.     echo "javascript:mySeFunc([".$myComboVar2."]);";
  26.  
I receive a parse error for the line after
Expand|Select|Wrap|Line Numbers
  1. if(strpos($myTempDirArray[$someVar], eval($myTempArray[$myNewCounter]))
  2.  
This should be pretty simple, right?

What am I missing?

Thanks in advance,
Tarik
Mar 11 '08 #1
Share this Question
Share on Google+
3 Replies


dlite922
Expert 100+
P: 1,584
If you like programming (and i hope you do) then you must LOVE algorithms in mathmatics applied to exactly what your doing:

http://www.aihorizon.com/essays/basi.../binsearch.htm

Here's more
http://www.ics.uci.edu/~eppstein/161/960215.html

I know i didn't really answer your particular problem, but giving you knowledge instead of a fix is my first choice most of the time

(And i actually gota go!)

Good luck
Mar 11 '08 #2

P: 63
Thanks, via the two cents of a buddy I've actually came across this way of comparing arrays, but the values within the arrays are not the same so I don't know how else to compare unlike arrays.

Expand|Select|Wrap|Line Numbers
  1. $myComboVar = array_intersect($myTempArray, $myTempDirArray);
  2.  
Here are the values of one index of the myTempArray:
Expand|Select|Wrap|Line Numbers
  1. {SHOWS:"no_show_selected ", FIRST_NAME:"tarik", LAST_NAME:"monem", PICTURE:"3059922480.jpg", EMAIL_ADDRESS:"t@bs.com", PHONE_NUMBER:"9999999999", CITY:"LA", STATE:"CA", ZIP:"91411", AGE:"24", GENDER:"MALE"}
  2.  
and the other is just the name of jpeg.

BTW, I was missing a ")" at the end of the conditional statement which was causing the parse error.
Mar 11 '08 #3

P: 63
Here's what I came up with, if anyone is interested:
Expand|Select|Wrap|Line Numbers
  1.     $myComboVar = array();
  2.     $myNewCounter=0;
  3.  
  4.     for($someVar=0;$someVar<count($myTempArray);$someVar++)
  5.     {
  6.             $myTempTempVar = $myTempArray[$myNewCounter];
  7.             $myTempTempTempVar = $myTempDirArray[$someVar];
  8.             $pattern ="/([a-zA-Z0-9])+".$myTempTempTempVar."([a-zA-Z0-9_-])+/";
  9.             if(preg_match($pattern, $myTempTempVar))
  10.             {
  11.                 $myComboVar[$someVar] = $myTempArray[$myNewCounter];
  12.             }
  13.         $myNewCounter++;
  14.     }
  15.  
It works, thanks for the help as usual and have a good one :-)
Mar 11 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.