What's the Maximum Value For an Int in PHP

What's the maximum value for an int in PHP?

From the PHP manual:

The size of an integer is
platform-dependent, although a maximum
value of about two billion is the
usual value (that's 32 bits signed).
PHP does not support unsigned
integers. Integer size can be
determined using the constant
PHP_INT_SIZE, and maximum value using
the constant PHP_INT_MAX since PHP
4.4.0 and PHP 5.0.5.

64-bit platforms usually have a maximum value of about 9E18, except on Windows prior to PHP 7, where it was always 32 bit.

PHP Largest Possible Integer Constant

From here:

PHP_INT_MAX (integer)
Available since PHP 4.4.0 and PHP 5.0.5

purpose of the max number in php & mysql

It's hardware limit of the CPU. You can still use bc math function to work with larger numbers. In mysql it is about aligning bytes, so it knows at which offset is which column.

The multiply result is converted to float.

INT max size for 32bit system

You are using the whole 32 bits. It's just that the default output functions interpret it as signed integer. If you want to display the value "raw" use:

printf("%u", -1);    //  %u for unsigned

Since PHP handles the integers signed internally however, you can only use bit arithmetics, but not addition/multiplication etc. with them - if you expect them to behave like unsigned ints.

What is the maximum value for an int32?

It's 2,147,483,647. Easiest way to memorize it is via a tattoo.

How to get max() of integer value from a varchar field in codeigniter?

First, make sure column rf_name data type should be integer/float, not varchar/string/text etc.

So, according to the data type of the column, it will not store any string value

$maxid = $this->db->query('SELECT MAX(rf_name) AS maxid FROM table')->row()->maxid;

OR

$this->db->select_max('rf_name');
$query = $this->db->get('table');

If you have both string and numeric values you have to do the following steps

  1. Get all values of column

    $this->db->select('rf_name');
    $this-db->from('table');
    $values = $this->db->get('table')->result_array();
  2. Get only values from an array

    $only_values= array();
    foreach($values as $value){
    if (is_numeric($value['rf_name'])) {
    array_push($only_values, $value['rf_name']);
    }
    }
  3. use max() and pass the array of values to get maximum numeric value from it.

    $max_value = max($only_values); 


Related Topics



Leave a reply



Submit