Results 1 to 2 of 2

Thread: filtering function

  1. #1
    alicia Guest

    filtering function

    Hi,

    I have a script (attached at the bottom of the page) that can display the output I want but now I have a big problem finding a way to filter the output so it will show the results as below.

    Code:
    <?php
    for($i = 0; $i < 10000; $i++){
    $formattedi = str_split(str_pad($i,4,'0',STR_PAD_LEFT));
    $count = array_count_values($formattedi);
    $min = min($count);
    $max = max($count);
    if($max == 1) $group = 'all different numbers';
    if($max == 2 and $min == 2) $group = 'same numbers in pair';
    if ($max == 3) $group = '3 same numbers';
    if ($max == 2 and $min ==1) $group = '2 same numbers only';
    if($max == 4) $group = '4 same numbers';
    $out[$group][] = implode('', $formattedi);
    }
    echo '<pre>', print_r($out), '</pre>';
    ?>

    This is the kind of output I tried to filter :

    assuming abcd represents 4 different digit and we need the following output from the script we have :
    ABCD , AABC , AABB and AAAB ...

    We can do the first one ABCD but not the following cases where similar digits are side by side

    For instance for
    e.g :
    AABC (4 digits number with 2 same numbers),
    it will show only something like 1123, 3122 and not display output like 2129, 1091. Remove those with 2 counts but not side by side.

    e.g :
    AAAB (3 digits number)
    will show 1112, 2333, 7999 from the script below but not 2322, 1121

    e.g :
    AABB
    will show 1122, 3344 but will not show 2211 (since it is repeating) and will not show 1221 since same digits are not side by side.

    Thanks.

  2. #2
    Join Date
    Apr 2009
    Location
    The toon
    Posts
    1,225
    id look into regular expressions to filter your content

    have a look here

    http://php.net/manual/en/function.preg-match.php

Similar Threads

  1. call to non-member function - need help!!
    By appleifreak in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 06 Jun 2009, 01:51 AM
  2. animation function not workin.. please advise
    By JasonChan in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 19 Feb 2007, 11:23 PM
  3. correct use of a function?
    By numbenator in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 24 Sep 2005, 09:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •