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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rich

    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?

  • rich

    #2
    Re: I keep getting this error in in_array. Any ideas why?

    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?

    Comment

    • Juliette

      #3
      Re: I keep getting this error in in_array. Any ideas why?

      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;
      }

      Comment

      • rich

        #4
        Re: I keep getting this error in in_array. Any ideas why?

        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;
        }

        Comment

        Working...