UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

69 lines (57 loc) 2.02 kB
--- layout: page title: "JavaScript is_integer function" comments: true sharing: true footer: true alias: - /functions/view/is_integer:445 - /functions/view/is_integer - /functions/view/445 - /functions/is_integer:445 - /functions/445 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's is_integer {% codeblock var/is_integer.js lang:js https://raw.github.com/kvz/phpjs/master/functions/var/is_integer.js raw on github %} function is_integer (mixed_var) { // From: http://phpjs.org/functions // + original by: Paulo Freitas // - depends on: is_int // % note 1: 1.0 is simplified to 1 before it can be accessed by the function, this makes // % note 1: it different from the PHP implementation. We can't fix this unfortunately. // * example 1: is_integer(186.31); // * returns 1: false // * example 2: is_integer(12); // * returns 2: true return this.is_int(mixed_var); } {% endcodeblock %} - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/var/is_integer.js) Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are the closest match to this hashtable-like data structure. Please also note that php.js offers community built functions and goes by the [McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just: - [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/var/is_integer.js) ### Example 1 This code {% codeblock lang:js example %} is_integer(186.31); {% endcodeblock %} Should return {% codeblock lang:js returns %} false {% endcodeblock %} ### Example 2 This code {% codeblock lang:js example %} is_integer(12); {% endcodeblock %} Should return {% codeblock lang:js returns %} true {% endcodeblock %} ### Other PHP functions in the var extension {% render_partial _includes/custom/var.html %}