You are here: Re: Searching through an array « All PHP « IT news, forums, messages
Re: Searching through an array

Posted by Phil on 08/22/06 18:05

On Tue, 22 Aug 2006 15:44:15 GMT, John Rappold wrote...
>
>-Lost,
>
>Thanks, that worked well.
>
>So that i can learn something and not have to ask a question in the same
>context, again, could you walk me through what these lines are doing:
>
>for($i = 0; $i < count($fields); $i++)
>{
> for($j = 0; $j < count($badchars); $j++)
>
>
>I understand that I have to traverse through both arrays, but I'm not sure
>what you did in the above lines.
>
>Later,
>jr


Within your first "for" loop, you are transversing through the $fields array.
The $i is starting with the first one "$fields[0]" and checking each of the
elements in that array until it gets to the last one.

While that "for" loop is running, the other "for" loop within it is transversing
the other array and using the "strpos" function to compare each element of
$badchars to the current element of $fields (generated from the primary "for"
loop). For each element of $fields, the $badchars array is being checked for a
match.

Phil
--
Newsguy - Basic Accounts - $39.95 / year



>"-Lost" <spam_ninjaREMOVEME@REMOVEMEcomcast.net> wrote in message
>news:9rqdncF-r5QiQHfZnZ2dnUVZ_q6dnZ2d@comcast.com...
>> "John Rappold" <jrappold@jscoca-k12.org> wrote in message
>> news:IKmGg.20285$uV.15613@trnddc08...
>>
>>> $dirn = substr($file, 0, 6);
>>> $birn = substr($file, 7, 6);
>>> $fdate = substr($file, 14, 8);
>>> $period = substr($file, 23, 5);
>>> $cat = substr($file, 29, 3);
>>>
>>> $fields = array($dirn, $birn, $fdate, $period, $cat);
>>>
>>> $badchars = array("-", "_");
>>
>> How about:
>>
>> for($i = 0; $i < count($fields); $i++)
>> {
>> for($j = 0; $j < count($badchars); $j++)
>> {
>> if(strpos($fields[$i], $badchars[$j]) === false)
>> {
>> continue;
>> }
>> else
>> {
>> print $fields[$i] . ' contained ' . $badchars[$j] . '<br />' . "\n";
>> }
>> }
>> }
>>
>> It may not be the most elegant solution, and using regular expressions
>> might make it considerably easier, but hey... it works efficiently.
>>
>> -Lost
>>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация