Connecting Tech Pros Worldwide Forums | Help | Site Map

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

rich
Guest
 
Posts: n/a
#1: Sep 18 '06
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($dresstypeid);
$primsecA=getprimsec();

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($specprimA) >0){
if (in_array($primsecA[$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($primsecA[$i]['primsecid'], $specprimA)) { ?>

Any ideas why?


rich
Guest
 
Posts: n/a
#2: Sep 18 '06

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


Oh here is the getspecprim() function

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

rich wrote:
Quote:
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($dresstypeid);
$primsecA=getprimsec();
>
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($specprimA) >0){
if (in_array($primsecA[$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($primsecA[$i]['primsecid'], $specprimA)) { ?>
>
Any ideas why?
Juliette
Guest
 
Posts: n/a
#3: Sep 19 '06

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


rich wrote:
Quote:
Oh here is the getspecprim() function
>
function getspecprim($dresstypeid) {
$getQ="SELECT primsecid FROM li_dresstypepsp
WHERE
dresstypeid= '$dresstypeid'";
$getR = pg_query($getQ);
$getA= pg_fetch_all($getR);
return($getA);
}
>
rich wrote:
Quote:
>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($dresstypeid);
>$primsecA=getprimsec();
>>
>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($specprimA) >0){
>if (in_array($primsecA[$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($primsecA[$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;
}
rich
Guest
 
Posts: n/a
#4: Sep 20 '06

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


Juliette that was a good idea. Thanks.

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

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

rich wrote:
Quote:
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($dresstypeid);
$primsecA=getprimsec();
>
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($specprimA) >0){
if (in_array($primsecA[$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($primsecA[$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;
}
Closed Thread