Checking if a value is repeated in an array

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

    Checking if a value is repeated in an array

    Hi everyone,

    I was wondering if its possible to check if a given value appears in
    an array more than once?

    I need to code something which goes something along the lines of:

    Faux code ---

    if (in_array_twice ($person, $already_emaile d)) {
    echo $person . ' is in the array already, don't email them';
    } else {
    echo $person . ' is not in the array, its OK to email them';
    }

    ---

    If anyone has any ideas they'd be very much appreciated.

    Thanks,

    OP

  • ZeldorBlat

    #2
    Re: Checking if a value is repeated in an array

    On Jul 9, 12:29 pm, odysseyphotogra phy <i...@odysseyph otography.net>
    wrote:
    Hi everyone,
    >
    I was wondering if its possible to check if a given value appears in
    an array more than once?
    >
    I need to code something which goes something along the lines of:
    >
    Faux code ---
    >
    if (in_array_twice ($person, $already_emaile d)) {
    echo $person . ' is in the array already, don't email them';} else {
    >
    echo $person . ' is not in the array, its OK to email them';
    >
    }
    >
    ---
    >
    If anyone has any ideas they'd be very much appreciated.
    >
    Thanks,
    >
    OP
    function in_array_moreth anonce($needle, array $haystack, $strict =
    false) {
    return (count(array_ke ys($haystack, $needle, $strict)) 1);
    }

    Comment

    • odysseyphotography

      #3
      Re: Checking if a value is repeated in an array

      Thank you so much, I'll give it a go...

      OP

      Comment

      • gosha bine

        #4
        Re: Checking if a value is repeated in an array

        On 09.07.2007 18:29 odysseyphotogra phy wrote:
        Hi everyone,
        >
        I was wondering if its possible to check if a given value appears in
        an array more than once?
        >
        I need to code something which goes something along the lines of:
        >
        Faux code ---
        >
        if (in_array_twice ($person, $already_emaile d)) {
        echo $person . ' is in the array already, don't email them';
        } else {
        echo $person . ' is not in the array, its OK to email them';
        }
        >
        ---
        >
        If anyone has any ideas they'd be very much appreciated.
        >
        Thanks,
        >
        OP
        >
        see array_count_val ues() and array_unique()



        --
        gosha bine

        extended php parser ~ http://code.google.com/p/pihipi
        blok ~ http://www.tagarga.com/blok

        Comment

        Working...