A little help with isset, in_array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vernon Wenberg III

    A little help with isset, in_array

    I am trying to search within an array to see if there is a match, but I
    can't get my head around these functions which are supposed to return
    TRUE or FALSE.

    First I get a list of values from a database and build an array with it
    with numerical indexes.

    When I finally do a comparison using both ...

    in_array($item_ link_md5, $real_id_array) ;
    isset($real_id_ array[$item_link_md5]);

    I get a number as it's return value and it seems to be the total number
    of values in the array, not a simple TRUE or FALSE.

    Where am I going wrong here?
  • Jerry Stuckle

    #2
    Re: A little help with isset, in_array

    Vernon Wenberg III wrote:
    I am trying to search within an array to see if there is a match, but I
    can't get my head around these functions which are supposed to return
    TRUE or FALSE.
    >
    First I get a list of values from a database and build an array with it
    with numerical indexes.
    >
    When I finally do a comparison using both ...
    >
    in_array($item_ link_md5, $real_id_array) ;
    isset($real_id_ array[$item_link_md5]);
    >
    I get a number as it's return value and it seems to be the total number
    of values in the array, not a simple TRUE or FALSE.
    >
    Where am I going wrong here?
    >
    What's your actual code? In both of these examples you're just throwing
    away the results of the function calls.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Vernon Wenberg III

      #3
      Re: A little help with isset, in_array

      Jerry Stuckle wrote:
      >
      What's your actual code? In both of these examples you're just throwing
      away the results of the function calls.
      >
      This is the basic code ...

      // build array from db results
      while ($id_array = mysql_fetch_arr ay($sql_id_matc hing_result)) {
      $real_item_id_a rray[] = $id_array['item_id'];
      }

      $item_link_md5 = 'test_var';

      if (isset($real_id _array[$item_link_md5])) {

      // do stuff here.

      }


      Comment

      • Vernon Wenberg III

        #4
        Re: A little help with isset, in_array

        Vernon Wenberg III wrote:
        Jerry Stuckle wrote:
        >>
        >What's your actual code? In both of these examples you're just
        >throwing away the results of the function calls.
        >>
        >
        This is the basic code ...
        >
        // build array from db results
        while ($id_array = mysql_fetch_arr ay($sql_id_matc hing_result)) {
        $real_item_id_a rray[] = $id_array['item_id'];
        }
        >
        $item_link_md5 = 'test_var';
        >
        if (isset($real_id _array[$item_link_md5])) {
        >
        // do stuff here.
        >
        }
        >
        >
        EDIT: *real_item_id_a rray in the if statement.

        Comment

        • Jerry Stuckle

          #5
          Re: A little help with isset, in_array

          Vernon Wenberg III wrote:
          Vernon Wenberg III wrote:
          >Jerry Stuckle wrote:
          >>>
          >>What's your actual code? In both of these examples you're just
          >>throwing away the results of the function calls.
          >>>
          >>
          >This is the basic code ...
          >>
          > // build array from db results
          > while ($id_array = mysql_fetch_arr ay($sql_id_matc hing_result)) {
          > $real_item_id_a rray[] = $id_array['item_id'];
          > }
          >>
          > $item_link_md5 = 'test_var';
          >>
          > if (isset($real_id _array[$item_link_md5])) {
          > // do stuff here.
          > }
          >>
          >>
          >
          EDIT: *real_item_id_a rray in the if statement.
          >
          OK, this is checking to see if $real_id_array['test_var'] is set.
          However, you added them with default indexes, so what you have in the
          array is:

          $real_id_array[0]
          $real_id_array[1]
          $real_id_array[2]
          $real_id_array[3]
          etc.

          So isset() will never return true.

          What are you TRYING to do?

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Vernon Wenberg III

            #6
            Re: A little help with isset, in_array

            Jerry Stuckle wrote:
            Vernon Wenberg III wrote:
            >Vernon Wenberg III wrote:
            >>Jerry Stuckle wrote:
            >>>>
            >>>What's your actual code? In both of these examples you're just
            >>>throwing away the results of the function calls.
            >>>>
            >>>
            >>This is the basic code ...
            >>>
            >> // build array from db results
            >> while ($id_array = mysql_fetch_arr ay($sql_id_matc hing_result)) {
            >> $real_item_id_a rray[] = $id_array['item_id'];
            >> }
            >>>
            >> $item_link_md5 = 'test_var';
            >>>
            >> if (isset($real_id _array[$item_link_md5])) {
            >> // do stuff here.
            >> }
            >>>
            >>>
            >>
            >EDIT: *real_item_id_a rray in the if statement.
            >>
            >
            OK, this is checking to see if $real_id_array['test_var'] is set.
            However, you added them with default indexes, so what you have in the
            array is:
            >
            $real_id_array[0]
            $real_id_array[1]
            $real_id_array[2]
            $real_id_array[3]
            etc.
            >
            So isset() will never return true.
            >
            What are you TRYING to do?
            >
            I'm trying to compare values from the DB which are now in an array to
            the a new value to find out if the new value exists in the DB.

            Thank you for the explanation. I've gotten it to work now after you
            pointed out the creation of my array was where I went wrong. I thought
            that isset was just giving me quirky results.

            Much thanks.

            Comment

            • George Maicovschi

              #7
              Re: A little help with isset, in_array

              On Apr 11, 3:45 am, Vernon Wenberg III <vwenb...@gmail .comwrote:
              Jerry Stuckle wrote:
              Vernon Wenberg III wrote:
              Vernon Wenberg III wrote:
              >Jerry Stuckle wrote:
              >
              >>What's your actual code? In both of these examples you're just
              >>throwing away the results of the function calls.
              >
              >This is the basic code ...
              >
              > // build array from db results
              > while ($id_array = mysql_fetch_arr ay($sql_id_matc hing_result)) {
              > $real_item_id_a rray[] = $id_array['item_id'];
              > }
              >
              > $item_link_md5 = 'test_var';
              >
              > if (isset($real_id _array[$item_link_md5])) {
              > // do stuff here.
              > }
              >
              EDIT: *real_item_id_a rray in the if statement.
              >
              OK, this is checking to see if $real_id_array['test_var'] is set.
              However, you added them with default indexes, so what you have in the
              array is:
              >
              $real_id_array[0]
              $real_id_array[1]
              $real_id_array[2]
              $real_id_array[3]
              etc.
              >
              So isset() will never return true.
              >
              What are you TRYING to do?
              >
              I'm trying to compare values from the DB which are now in an array to
              the a new value to find out if the new value exists in the DB.
              >
              Thank you for the explanation. I've gotten it to work now after you
              pointed out the creation of my array was where I went wrong. I thought
              that isset was just giving me quirky results.
              >
              Much thanks.
              Then the if should be:
              if (in_array($item _link_md5,$real _item_id_array) )
              //do stuff here

              Cheers,
              George.

              Comment

              Working...