I am wondering if I can set a variable to infinity, and if not what the best way to achieve my problem is. Take my function below:
public function seekValue($value, $column = null, $limit = null) {
$this->connect('rb');
$results = array();
while (!feof($this->_pointer)) {
$data = explode($this->_config->delimiter(), fgets($this->_pointer, 1024));
if(!is_null($column)) {
if ($data[$this->_config->columns($column, "string")->index()] == $value)
array_push($results, $this->formatRow($data));
} else {
if (in_array($value, $data))
array_push($results, $this->formatRow($data));
}
}
$this->disconnect();
switch (count($results)) {
case 0;
return false;
case 1;
return $results[0];
default;
return $results;
}
}
I set $limit = null
in the function parameter list, however I later want to use $limit
in my while loop like so while (!feof($this->_pointer) && count($results) < $limit)
incase the user decides to pass an integer to it.
If this was the case I could do this:
if (!is_int($limit)) {
$limit = infinity;
}
To say that if $limit
is not set run infinite times.
I hope this makes sense.
The is_infinite() function checks whether a value is infinite or not. This function returns true (1) if the specified value is an infinite number, otherwise it returns false/nothing. The value is infinite if it is outside the allowed range for a PHP float on this platform.
PHP doesn't by default make a variable integer or string, if you want to set default value, then simply write $myvariable = 0; and this will assign and make variable an integer type.
The is_int() function checks whether a variable is of type integer or not. This function returns true (1) if the variable is of type integer, otherwise it returns false.
Definition and UsageThe is_numeric() function checks whether a variable is a number or a numeric string. This function returns true (1) if the variable is a number or a numeric string, otherwise it returns false/nothing.
Just to answer the original question:
Yes you can set a variable to infinity by assigning INF
$x = INF;
var_dump($x > 10000); // bool(true)
var_dump($x - 100); // float(INF)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With