PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



array filter

 
Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General
View previous topic :: View next topic  
Author Message
alicia



Joined: 17 Jun 2004
Posts: 17

PostPosted: Tue Nov 24, 2009 4:42 pm    Post subject: array filter Reply with quote

Hi,

I was trying to set the same digits that are not side by side, won't be displayed in the output.. how can I edit the script below to accomplish the following ?

For instance for
e.g :
AABC (4 digits number),
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

Please advise. Thank you.

[code:1]
<?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>';
?>

[/code:1]


Thank you
Back to top
View user's profile Send private message
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum