Jump to content

Removing numbers from a set of numbers


thefollower

Recommended Posts

Hey guys quick question

 

Say theres a limit of number choices from 1 to 10. (not including 0)

 

Now these numbers are buyable so say some one buys number 7.

 

With a query or what ever is needed i need to find a way for the screen to then display:

 

1 2 3 4 5 6 8 9 10.

 

As you notice 7 is not missing.. but it could be any number and more than one number that has already been taken...

 

How can this be done in PHP and MYSQL or will it require some other script?

Link to comment
https://forums.phpfreaks.com/topic/78437-removing-numbers-from-a-set-of-numbers/
Share on other sites

At it's simplest:

 

<?php
$choices = array(1,2,3,4,5,6,7,8,9,10);
$used = array(5,7);
$possible = array_diff($choices,$used);
$possible = implode(',',$possible);
echo $possible;
?>

 

It really depends on what its for as to how you would actually do it.

Well i can tell you in a more complex way:

 

Say you want to buy a house in a street.. so you pick the street then it gets all houses in that street.. when it has got all these houses it will know what numbers are already taken... processing wise i can easily do a validation check.

But to stop users guessing which house numbers are not free by constantly inputting numbers..

 

I would rather it echo out the numbers that are still available from stripping out the numbers that are taken from the string then echo it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.