PHP Puzzlet.
Feb. 22nd, 2006 01:21 pmI'm kinda new to PHP, and I'm wondering what is the best way to perform this operation:
I have three variables, $a, $b and $c. Each contains either a single character, or nothing.
What's the best way to test that no two defined values are the same?
Heck, I'm not even sure what the best way to do this would be in Perl, allthough I have a few ideas involving hashes.
I have three variables, $a, $b and $c. Each contains either a single character, or nothing.
What's the best way to test that no two defined values are the same?
Heck, I'm not even sure what the best way to do this would be in Perl, allthough I have a few ideas involving hashes.
no subject
Date: 2006-02-22 07:09 pm (UTC)sub coll(@) {my %a; @a{@_}=(); @_ == keys %a}or more sensibly if less tersely
sub coll(@) {my %a; for my $a (@_) {return undef if $a{$a}++}; 1}no subject
Date: 2006-02-22 07:26 pm (UTC)$a ne $b && $a ne $c && $b ne $cis likely fastest.no subject
Date: 2006-02-22 08:14 pm (UTC)no subject
Date: 2006-02-22 09:18 pm (UTC)sub coll(@) {my @a = grep $_, @_; %a; @a{@a}=(); @a == keys %a}or
sub coll(@) {my %a; for my $a (@_) {return undef if $a && $a{$a}++}; 1}—but of course, that's still just Perl.