Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/254729-is-it-possible-to-say-infinite-with-php/
Share on other sites

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

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.

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?

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.

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));

?> 

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

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

 

 

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.

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().

 

 

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

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?

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.