Shadowing Posted January 10, 2012 Share Posted January 10, 2012 was wondering if it is possible to write infinite in php. so when php reads it its accepted as the most highest number. i was looking at the is infinite function but i dont think thats what im looking for. I was also reading something about how that any number over 170 characters in lenght is consider infinite in php Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/ Share on other sites More sharing options...
ManiacDan Posted January 10, 2012 Share Posted January 10, 2012 What problem are you attempting to solve here? Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306149 Share on other sites More sharing options...
Shadowing Posted January 10, 2012 Author Share Posted January 10, 2012 some times i want $naq to be infinite so it doesnt end up being the min number $max = min(array($sym, $res, $naq)); atm im using $naq= 1000000000000000000; which works but was wondering if i could type a easy way of php reading it as infinite also sym, and res could end up being infinite as well Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306155 Share on other sites More sharing options...
ManiacDan Posted January 10, 2012 Share Posted January 10, 2012 1) You don't need the array declaration in there, min() supports an infinite number of arguments. 2) Simply remove $maq entirely. You're asking "I want the minimum of two numbers, or infinity." Infinity is never the minimum of any set, just remove it. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306164 Share on other sites More sharing options...
Shadowing Posted January 10, 2012 Author Share Posted January 10, 2012 Thanks for the replies ManiacDan I was wanting to make it infinite so it doesnt become the min. So im trying to force it to be the max in the array Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306245 Share on other sites More sharing options...
ManiacDan Posted January 10, 2012 Share Posted January 10, 2012 Yes, obviously, so what you're saying is: "I have three numbers: 4, 9, 18. I want to find the minimum of these numbers, but I don't want to count the middle one, so how do I make it infinite?" Don't include it, and it can't possibly be the min...because it's not included. Call the function without that variable, and it can't possibly be the answer. What am I missing here? Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306246 Share on other sites More sharing options...
Shadowing Posted January 10, 2012 Author Share Posted January 10, 2012 im starting to think that maybe i shouldnt try to do stuff with less amount of code as possible. I dont think i realize how fast computers really are on reading scripts even with alot of users. So alot of times im always thinking of not using addional if statements and etc. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306266 Share on other sites More sharing options...
requinix Posted January 10, 2012 Share Posted January 10, 2012 You don't need more code for this. $max = min(array($sym, $res)); There. Do you understand it now? If you don't ever want $naq to be the minimum then don't include it in the list. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306291 Share on other sites More sharing options...
Shadowing Posted January 11, 2012 Author Share Posted January 11, 2012 all 3 variables are variables that can change If I decide to change one of the variables to 0 id want it to not end up as the minium I have a page that allows me to change any of those 3 variables into 0. When I do change it into 0 i dont want it to end up as the min. I also may change two of the variables to 0. if any of those ever was 0 then force it to equal a number that could never become the min in the array <?php if ($sym == 0) { $sym = 1000000000000000000;} if ($res == 0) { $res = 1000000000000000000;} if ($naq == 0) { $naq = 1000000000000000000;} $max = min(array($sym, $res, $naq)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306446 Share on other sites More sharing options...
PFMaBiSmAd Posted January 11, 2012 Share Posted January 11, 2012 For the lowest, non-zero value - $lowest = min(array_filter(array($sym, $res, $naq))); Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306451 Share on other sites More sharing options...
Shadowing Posted January 11, 2012 Author Share Posted January 11, 2012 oh wow thank you PFMaBiSmAd thats what i was looking for. I didnt even think of looking in the manual for something that excludes 0's Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306454 Share on other sites More sharing options...
Shadowing Posted January 11, 2012 Author Share Posted January 11, 2012 oh wait that function doesnt let me use more then 2 parameters. damn lol Warning: array_filter() expects at most 2 parameters, 3 given using that same kinda thought is there a INT function that lets me simply ignore the variable from the start if its a 0 before it even lands in the array Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306457 Share on other sites More sharing options...
PFMaBiSmAd Posted January 11, 2012 Share Posted January 11, 2012 Cannot help you with your latest problem without the relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306458 Share on other sites More sharing options...
Shadowing Posted January 11, 2012 Author Share Posted January 11, 2012 these 3 variables can be changed to 0 at any time and when they do equal 0 i dont want it to end up as the min <?php $sym = 10; $res = 5; $naq = 0; $lowest = min(array_filter($sym, $res, $naq)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306459 Share on other sites More sharing options...
PFMaBiSmAd Posted January 11, 2012 Share Posted January 11, 2012 Programming is an exact science. If you couldn't copy/paste the line of code I posted for some reason, at least proof read the line of code you wrote and compare it with the line of code you were given. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306465 Share on other sites More sharing options...
ManiacDan Posted January 11, 2012 Share Posted January 11, 2012 In addition, this whole thing could have been worked around with an IF statement without any ill effects on your code. In fact, I bet the IF solution is a little faster than array_filter. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306470 Share on other sites More sharing options...
Shadowing Posted January 11, 2012 Author Share Posted January 11, 2012 as a note I just found something that works instead of trying to turn it into a infinite number. All i had to do is just empty the variable. <?php if ($naq == 0) { $naq = empty($naq);} $lowest = min(array($sym, $res, $naq)); ?> Anyways yah i dont like to copy and paste to much cause since im still a noob at this it helps me learn by typing it in manually. for now on i'll do a double check thanks a ton major help PFMaBiSmAd i see whats going on here i just learn something. array_filter is a function for the array Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306472 Share on other sites More sharing options...
Shadowing Posted January 11, 2012 Author Share Posted January 11, 2012 getting rid of the if statement acctually got rid of 21 lines of code cause i had 7 groups with 3 if statements in each. excluding speed as a issue it clean the page up alot. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306473 Share on other sites More sharing options...
ManiacDan Posted January 11, 2012 Share Posted January 11, 2012 If we saw all your code and you told us the reason behind it, I'm sure we could figure out a way to utilize arrays properly and pare the size down a lot. However, if it's working it's working. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306534 Share on other sites More sharing options...
Alex Posted January 11, 2012 Share Posted January 11, 2012 All i had to do is just empty the variable. In order to prevent any misconception, unless you only worded that badly, empty doesn't "empty the variable". It simply returns whether or not the variable is empty, as the manual states with more detail. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306659 Share on other sites More sharing options...
ManiacDan Posted January 12, 2012 Share Posted January 12, 2012 Right, what you were doing was assigning $naq to the result of "is $naq empty?" Since $naq was not empty, the result of empty($naq) was false, which isn't a number, which is why it doesn't count in min(). Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1306802 Share on other sites More sharing options...
Garethp Posted January 13, 2012 Share Posted January 13, 2012 these 3 variables can be changed to 0 at any time and when they do equal 0 i dont want it to end up as the min <?php $sym = 10; $res = 5; $naq = 0; $lowest = min(array_filter($sym, $res, $naq)); ?> Look at PFMaBiSmAd's code. Now back to your code, now back to his. Is your code his? No, but if could be if you put those three variables into an array BEFORE putting them through a function that filters an array Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1307132 Share on other sites More sharing options...
Shadowing Posted January 13, 2012 Author Share Posted January 13, 2012 ah wow i didnt know that was what was going on when i was using empty. Thanks alot guys. Thats very useful to know. So if I say a variable is empty and then say its !empty It will read whats in the variable again? Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1307202 Share on other sites More sharing options...
ManiacDan Posted January 13, 2012 Share Posted January 13, 2012 You're still not really understanding: empty() is a function that checks to see if the variable is empty. If it is, empty() returns true. Otherwise, false. Once you overwrite a variable with something else, you cannot recover the old value. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1307225 Share on other sites More sharing options...
Shadowing Posted January 13, 2012 Author Share Posted January 13, 2012 ahh ok i see whats going on. Im not sure if i worded it badly earlier or not or I really did think at the time it was emptying it. I cant remember. nice to know i can only use empty as just checking if something is empty or not. Quote Link to comment https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/#findComment-1307274 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.