473,792 Members | 3,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I keep getting this error in in_array. Any ideas why?

I keep getting the error:
Warning: in_array(): Wrong datatype for second argument on line 679
here is the code.
I declare and fill the array
$specprimA = array();
$specprimA= getspecprim($dr esstypeid);
$primsecA=getpr imsec();

Then I do a compare using in Array. I even put in the extra step of
making sure I have something in the array with the is sizeof statement.

$numcl= count($primsecA );
for ($i=0; $i<$numcl; $i++){
$primsec = $primsecA[$i]['primsec'];
if (sizeof($specpr imA) >0){
if (in_array($prim secA[$i]['primsecid'], $specprimA)) { ?>
<input type="checkbox" checked tabindex="2" name="primsecid[]"
value="<?php echo $primsecA[$i]['primsecid']; ?>"/><?php echo
$primsec;
} else { ?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}
} else { ?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}
}?>

This is line 679
if (in_array($prim secA[$i]['primsecid'], $specprimA)) { ?>

Any ideas why?

Sep 18 '06 #1
3 1791
Oh here is the getspecprim() function

function getspecprim($dr esstypeid) {
$getQ="SELECT primsecid FROM li_dresstypepsp
WHERE
dresstypeid= '$dresstypeid'" ;
$getR = pg_query($getQ) ;
$getA= pg_fetch_all($g etR);
return($getA);
}

rich wrote:
I keep getting the error:
Warning: in_array(): Wrong datatype for second argument on line 679
here is the code.
I declare and fill the array
$specprimA = array();
$specprimA= getspecprim($dr esstypeid);
$primsecA=getpr imsec();

Then I do a compare using in Array. I even put in the extra step of
making sure I have something in the array with the is sizeof statement.

$numcl= count($primsecA );
for ($i=0; $i<$numcl; $i++){
$primsec = $primsecA[$i]['primsec'];
if (sizeof($specpr imA) >0){
if (in_array($prim secA[$i]['primsecid'], $specprimA)) { ?>
<input type="checkbox" checked tabindex="2" name="primsecid[]"
value="<?php echo $primsecA[$i]['primsecid']; ?>"/><?php echo
$primsec;
} else { ?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}
} else { ?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}
}?>

This is line 679
if (in_array($prim secA[$i]['primsecid'], $specprimA)) { ?>

Any ideas why?
Sep 18 '06 #2
rich wrote:
Oh here is the getspecprim() function

function getspecprim($dr esstypeid) {
$getQ="SELECT primsecid FROM li_dresstypepsp
WHERE
dresstypeid= '$dresstypeid'" ;
$getR = pg_query($getQ) ;
$getA= pg_fetch_all($g etR);
return($getA);
}

rich wrote:
>I keep getting the error:
Warning: in_array(): Wrong datatype for second argument on line 679
here is the code.
I declare and fill the array
$specprimA = array();
$specprimA= getspecprim($dr esstypeid);
$primsecA=getp rimsec();

Then I do a compare using in Array. I even put in the extra step of
making sure I have something in the array with the is sizeof statement.

$numcl= count($primsecA );
for ($i=0; $i<$numcl; $i++){
$primsec = $primsecA[$i]['primsec'];
if (sizeof($specpr imA) >0){
if (in_array($prim secA[$i]['primsecid'], $specprimA)) { ?>
<input type="checkbox" checked tabindex="2" name="primsecid[]"
value="<?php echo $primsecA[$i]['primsecid']; ?>"/><?php echo
$primsec;
} else { ?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}
} else { ?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}
}?>

This is line 679
if (in_array($prim secA[$i]['primsecid'], $specprimA)) { ?>

Any ideas why?

count / sizeof on a boolean or string will return 1, so try changing the
line above the problem line to:
if( is_array( $specprimA ) && count( $specprimA ) 0 ) {

Alternatively, IMHO a better solution, would be to do the checking /
typecasting in the function.

replace:
return($getA);

with something along the lines of:
if( !is_array( $getA ) {
return array();
}
else {
return $getA;
}
Sep 19 '06 #3
Juliette that was a good idea. Thanks.

Juliette wrote:
rich wrote:
Oh here is the getspecprim() function

function getspecprim($dr esstypeid) {
$getQ="SELECT primsecid FROM li_dresstypepsp
WHERE
dresstypeid= '$dresstypeid'" ;
$getR = pg_query($getQ) ;
$getA= pg_fetch_all($g etR);
return($getA);
}

rich wrote:
I keep getting the error:
Warning: in_array(): Wrong datatype for second argument on line 679
here is the code.
I declare and fill the array
$specprimA = array();
$specprimA= getspecprim($dr esstypeid);
$primsecA=getpr imsec();

Then I do a compare using in Array. I even put in the extra step of
making sure I have something in the array with the is sizeof statement.

$numcl= count($primsecA );
for ($i=0; $i<$numcl; $i++){
$primsec = $primsecA[$i]['primsec'];
if (sizeof($specpr imA) >0){
if (in_array($prim secA[$i]['primsecid'], $specprimA)) { ?>
<input type="checkbox" checked tabindex="2" name="primsecid[]"
value="<?php echo $primsecA[$i]['primsecid']; ?>"/><?php echo
$primsec;
} else { ?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}
} else { ?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}
}?>

This is line 679
if (in_array($prim secA[$i]['primsecid'], $specprimA)) { ?>

Any ideas why?


count / sizeof on a boolean or string will return 1, so try changing the
line above the problem line to:
if( is_array( $specprimA ) && count( $specprimA ) 0 ) {

Alternatively, IMHO a better solution, would be to do the checking /
typecasting in the function.

replace:
return($getA);

with something along the lines of:
if( !is_array( $getA ) {
return array();
}
else {
return $getA;
}
Sep 20 '06 #4

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

Similar topics

12
6014
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); } }
6
4049
by: Craig Keightley | last post by:
I am trying to compare values of a string entered into an array but having no results, is this possible to achieve: <?php $ids = $row_rsProduct; // A comma separated list of values (1,2,3,4,5,6,7,8) $list = array($ids); if (in_array(1, $list)) { echo "In List";
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);
8
10255
by: Lisa | last post by:
I have a drop down that defaults to "select" after the page refreshes. How do I keep the selected value in the dropdown field... I've tried EVERYTHING and nothing works! :( <script LANGUAGE="JavaScript"> function getServer(form){ var cdoServerName = document.frmSoftware.cdoServerName.options.value;
2
2024
by: iainw | last post by:
HI All, 1st post here, i wonder if you can help. We are about to upload CMS t a windows server and keep getting 2 errors below. We need to go LIVE an it's delaying us. An error occured when updating the database. The likely reason is that write permissions are not set on th 'database' folder. Please remember that write and delete permissions are also required o the 'content' folder and its subfolders.
1
287
by: scuniverse | last post by:
Any ideas how to make a email report of all the error messages? I've read on php.net how to do it the problem is that it sends a email for each error instead of sending a single email with all the errors. The code I have thus far (sams as php.net less a few lines I didnt need): // user defined error handling function function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
4
8014
by: Gary | last post by:
Hi, I get this error " " when my web page run, what does it mean? Hope someone can help!!! Gary
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.
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
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,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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
5436
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.