Connecting Tech Pros Worldwide Help | Site Map

What is wrong here with in_array?

Sonnich
Guest
 
Posts: n/a
#1: Jan 16 '07
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++;
}

P Pulkkinen
Guest
 
Posts: n/a
#2: Jan 16 '07

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.



Sonnich
Guest
 
Posts: n/a
#3: Jan 16 '07

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

Rik
Guest
 
Posts: n/a
#4: Jan 16 '07

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


Closed Thread