473,791 Members | 2,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($f olders,
$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\wwwr oot\some_file.p hp 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($f olders, $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($Detail s6[$j], $options1[$k])!==false))
if(!in_array($f olders, $options1[$k])) // here it does
not
$folders[]=$options1[$k];
$k++;
}
}
$j++;
}

Jan 16 '07 #1
3 1889
I reply to writer's this sentence only:
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.

Jan 16 '07 #2

P Pulkkinen wrote:
I reply to writer's this sentence only:
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

Jan 16 '07 #3
Rik
Sonnich wrote:
P Pulkkinen wrote:
>I reply to writer's this sentence only:

>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
Jan 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2602
by: S.Shaigany | last post by:
Hi everybody, Please help me. I have a problem with my login page, which worked fine during the last one month. I have'nt made any changes in it. but from yesterday on, it seems that my PHP code receives wrong POST variables. This is my HTML code piece which just produces login form: <form name="login" action="default.php" method="post"> UserName:<input type="text" name="username" size="15" maxlength="20"
0
1554
by: Google Mike | last post by:
Imagine your web hosting provider just permitted you to type *.mydomain.com and you still get to the mydomain.com website that they host for you. Imagine you want to setup websites for your family like dad.mydomain.com, mom.mydomain.com, etc. Well, this is a request and some information for you. First, here's how you could use PHP to react to what they type in the URL: <!-- save as index.php in /var/www/html on Linux Apache: --> <?php
12
6013
by: AJ Z | last post by:
I am using in_array() to search for a value ("other"), in order to validate a form. If I pass $_POST as the array to search PHP says that it is an invalid datatype. It is an array and if I copy it to another variable (i.e. $list = $_POST;) it works fine. The same is also true of implode(). Do you believe this is intended or is it a bug? --
3
10693
by: Phil Powell | last post by:
if (is_array($_POST)) { foreach ($this->getAssocSectionsObjArray($key, $dbAP) as $obj) { print_r($obj); print_r(" in array? "); print_r(in_array($obj, $result)); print_r("<P>"); if (!in_array($obj, $result)) array_push($result, $obj); } }
3
2275
by: Tom Barnes | last post by:
Check out this code: // Start Code ------------- function test_in_array($val) { $a = array('key' => $val); printf("in_array: %d, value:%s<BR>", in_array('key', $a), $a); } test_in_array(0); test_in_array(1);
6
3285
by: Berimor | last post by:
Hi, i've been always used the in_array() function to check availabylity of a value in array. Until today. Simple code: (do not run it tho :) ) <? function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); }
6
1321
by: Jeff Gardner | last post by:
Greetings: I am attempting to get conditional output based on POSTed form data. If the posted value is either the key or value of an array, $x=key and $q=foo. elseif it is neither key nor value(I tried || too) , $q=bar. Even though $x is properly assigned the new value, $q always ends up being bar. Abstractions aside, here's the code: (note ## comments added to this post) <snip>
0
1089
by: rich | last post by:
I have 2 arrays. I am trying to use in_array with and it doesn't seem to be working. I have done a print_r of each one for my test data. Array $primsecA is below: Array ( =Array ( =1 =Primary ) => Array ( =2 =Secondary ) =Array ( =3 =Skin Protectors ) ) Array $specprimA is below.
2
1931
by: Nosferatum | last post by:
This script is meant to limit access by sessions, using username and password from mysql db and redirect users after login according to a given value belonging to each user in the db (10,20,30,40). (the included config is just server settings, the login is just a login form). The script appear to connect but will not redirect users, it seems that even with correct login details, it won't validate.
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.