Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 11-22-2008, 02:58 PM   #1
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,482
exclusive value in array [php]

I'm fucking with this script and i need toi get this simple thing done.

a. array(100,200,400);
b. array(100);
c. array(200);

100 is my goal here. I need to know what array has ONLY 100 in there (b.).


Any kids drinking at home tonight?
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:09 PM   #2
Alky
Confirmed User
 
Alky's Avatar
 
Join Date: Apr 2002
Location: Houston
Posts: 5,651
probably a better way to do it then i did it...and i didnt test it
Code:
fuction chkArr($array) {
foreach($array as $k=>$v) {
if($v!=100) {
return False;
} else {
$didfind=True;
}
}
if($didfind==True) {
return true;
} else {
return false;
}
}
Alky is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:17 PM   #3
Alky
Confirmed User
 
Alky's Avatar
 
Join Date: Apr 2002
Location: Houston
Posts: 5,651
yea you can you in_array() in place of some of my code above
Alky is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:34 PM   #4
Varius
Confirmed User
 
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
This should have you on your way

Code:
$array = array(array(100,200,400), array(100), array(200));

foreach ($array as $array2) {
        if ($array2[0]==100 && count($array2)==1) {
                $arrMatches[] = $array2;
        }
}

print_r($arrMatches);
I made an array there out of the arrays that ONLY contained the value 100, but you could just echo out the keys instead or whatever ya like.
__________________
Skype variuscr - Email varius AT gmail
Varius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:34 PM   #5
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,482
Nope, i have that
if (in_array(200,$p2osArr)){print "okay ja -> ";}

But this does not ISOLATE 100, it just looks if it there.
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:36 PM   #6
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,482
@Varius: I'll check that. At first glance, what if the array has 2x100. Like this:
$a = array(100,200,100,400);
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:38 PM   #7
Alky
Confirmed User
 
Alky's Avatar
 
Join Date: Apr 2002
Location: Houston
Posts: 5,651
Quote:
Originally Posted by Varius View Post
This should have you on your way

Code:
$array = array(array(100,200,400), array(100), array(200));

foreach ($array as $array2) {
        if ($array2[0]==100 && count($array2)==1) {
                $arrMatches[] = $array2;
        }
}

print_r($arrMatches);
I made an array there out of the arrays that ONLY contained the value 100, but you could just echo out the keys instead or whatever ya like.
not sure if he will run into the problem, but if the array has 100 twice it fails.
Alky is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:38 PM   #8
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,482
Oh, and there's one array, i should have written this:
$a = array(100,200,400);
$a = array(100,200,100,400);
$a = array(100);
$a = array(200);
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:40 PM   #9
Alky
Confirmed User
 
Alky's Avatar
 
Join Date: Apr 2002
Location: Houston
Posts: 5,651
Quote:
Originally Posted by Naughty View Post
Oh, and there's one array, i should have written this:
$a = array(100,200,400);
$a = array(100,200,100,400);
$a = array(100);
$a = array(200);
uhm, thats impossible if you do it after those 4 lines...you are making a new array each line.

so the array only has 200 in it.
Alky is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:51 PM   #10
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,482
Quote:
Originally Posted by Alky View Post
uhm, thats impossible if you do it after those 4 lines...you are making a new array each line.

so the array only has 200 in it.
That was an example of how the arrays would like when being checked. I thought that was obvious, sorry.
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:54 PM   #11
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,482
i'm a genius, i'm on to something ...
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:57 PM   #12
gornyhuy
Chafed.
 
gornyhuy's Avatar
 
Join Date: May 2002
Location: Face Down in Pussy
Posts: 18,041
Varius got it right. It doesn't fail on multiple 100's. You are asking if it has only one value and if that value is 100. That is what he is checking for.

His first condition checks for value of 100. His second condition checks if there is more than one value. Done.
__________________

icq:159548293
gornyhuy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 03:59 PM   #13
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,482
THIS does exactly what i want:
Code:
$a = array(100,100,100);
//$a = array(200,100,100);
if (in_array(100,$a)){
$tTnt_cnt = array_sum($a);
$tItems_cnt = count($a);

print (($tTnt_cnt/$tItems_cnt) > 100)?"parcel":"envelope";

}
__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-22-2008, 04:07 PM   #14
Naughty
Confirmed User
 
Industry Role:
Join Date: Jul 2001
Location: Utopia
Posts: 6,482
Even better, now when they have 4+ items, they have to get parcelpackaging anyhow;-)
*pads self on the back

PHP Code:
$a = array(100,100,100);
//$a = array(200,100,100);
if (in_array(100,$a)){
$tTnt_cnt array_sum($a);
$tItems_cnt count($a);
print ((
$tTnt_cnt/$tItems_cnt) == 100 && $tItems_cnt<=3)?"envelope":"parcel";

__________________
seks.ai for sale - ping me
Naughty is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.