• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Twig - How to check if variable is a number / integer

phptypestwigsymfony


PHP Snippet 1:

{% if foo is numeric %}...{% endif %}

PHP Snippet 2:

namespace MyNamespace;
class MyTwigExtension extends \Twig_Extension
{

    public function getName()
    {
        return 'my_twig_extension';
    }

    public function getTests()
    {
        return [
            new \Twig_Test('numeric', function ($value) { return  is_numeric($value); }),
        ];
    }
}

PHP Snippet 3:

services:
    my_twig_extension:
        autowire: true
        class: AppBundle\MyNamespace\MyTwigExtension
        tags:
            - { name: twig.extension }

Related Snippets

PHP Include for HTML?

Upload a file Using PHP and JavaScript

Entity provider not working in security.yml php symfony3.4 ({"code":401,"message":"bad credentials"}.)

How can I make this nested location configuration use the correct path to call a php program?

php script to delete files older than 24 hrs, deletes all files

Insert And Retrieve Data in MySQL with $.post Noob Question

Alert message after submitting form in PHP

PHP Startup Unable to load dynamic library /usr/lib/php/20151012/php_mysqli.dll

Need to display only array value in JSON output

Apply filter array/return terms

In PHP, which is faster: preg_split or explode?

Laravel 5.1 Unknown database type enum requested

Why rand() every time I refresh the page?

How to display MySQL table using php and edit it in a web browser

Dropdown with current value from Mysql

About Contact Privacy policy Terms and conditions