Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 16th, 2007, 08:55 AM
Sonnich
Guest
 
Posts: n/a
Default What is wrong here with in_array?

The following code is an exact copy of my current code.
The idea is to check 2 parts (of string arrays), and add those only
once to a common array.
I check for existance of an array in a string, as the string contain
more data that just .... well, the part from the options array is
there, then it is added to the folders array.

The problem is the line: if(!in_array($folders,
$options1[$k]))
which works in the first case, but not in the other, even that it is
copy-paste.
The entire things works as excepted, though I get the error:

Warning: in_array() [function.in-array]: Wrong datatype for second
argument in C:\Inetpub\wwwroot\some_file.php on line 754

The code follows
Sonnich


if($part9[$i]<>"")
{
$k=0;
while($k<count($options1))
{
if( (strpos($part9[$i], $options1[$k])!==false))
if(!in_array($folders, $options1[$k])) // here it works
$folders[]=$options1[$k];
$k++;
}
}
$j=0;
while(($j<count($Details0)) && ($Details0[$j]!=$part0[$i]) )
$j++;
while(($j<count($Details0)) && ($Details0[$j]==$part0[$i]) )
{
if($Details6[$j]<>"")
{
$k=0;
while($k<count($options1))
{
if( (strpos($Details6[$j], $options1[$k])!==false))
if(!in_array($folders, $options1[$k])) // here it does
not
$folders[]=$options1[$k];
$k++;
}
}
$j++;
}

  #2  
Old January 16th, 2007, 09:25 AM
P Pulkkinen
Guest
 
Posts: n/a
Default Re: What is wrong here with in_array?

I reply to writer's this sentence only:
Quote:
I check for existance of an array in a string, ...
With 'in_array' you can check (afaik)
- existence of a string in an array
- existence of an array in another array (since php 4.2)

bool in_array ( mixed needle, array haystack [, bool strict] )

Haystack is never a string, always an array.

But since php does autoconversion things, perhaps thats why you only get
warning level error.

But I didn't go through the actual code, this was just a guess.



  #3  
Old January 16th, 2007, 10:45 AM
Sonnich
Guest
 
Posts: n/a
Default Re: What is wrong here with in_array?


P Pulkkinen wrote:
Quote:
I reply to writer's this sentence only:
Quote:
bool in_array ( mixed needle, array haystack [, bool strict] )
>
Haystack is never a string, always an array.
But I didn't go through the actual code, this was just a guess.
heh - that was it. I had those mixed up. I was probably to tired when I
wrote that :-)

Thanks

  #4  
Old January 16th, 2007, 07:55 PM
Rik
Guest
 
Posts: n/a
Default Re: What is wrong here with in_array?

Sonnich wrote:
Quote:
P Pulkkinen wrote:
Quote:
>I reply to writer's this sentence only:
>
>
Quote:
>bool in_array ( mixed needle, array haystack [, bool strict] )
>>
>Haystack is never a string, always an array.
>But I didn't go through the actual code, this was just a guess.
>
heh - that was it. I had those mixed up. I was probably to tired when
I wrote that :-)
Hehe, I still get them mixed up too, for some reason it's some weakness of
mine...

What help is comparing the saying "tofind a needle(1) in a haystack(2)" to
the wrong "to search a haystack(1) for a needle(2)", which luckily works
with the identical saying in dutch for me :-).
--
Rik Wasmus


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles