• 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

Fatal error: Trait 'LaminasDbAdapterLaminasDbAdapterAdapterInterface' not found in /var/www/vendor/laminas/laminas-db/src/Adapter/Adapter.php

How to properly set "0000-00-00 00:00:00" as a DateTime in PHP

Encrypt in php and decrypt in Dart(flutter)

Converting IPv6 to IPv4 address in PHP

java URL working on browser but not in client program

VichUploaderBundle error "Expected argument of type "File", "NULL" given" when submitting the form without selecting any file

CSS file not imported in laravel blade view

Handle error for duplicate entries - PHP/MySQL

Clients authentication and user authentication with laravel

Redis Command To Sort Keys

Malformed MIME header error in Symfony 5.3

Can't exclude directories from .htaccess mobile redirect?

Laravel relationship belongsToMany with composite primary keys

How to give apache permission to write to home directory?

Invalid value in field "itemtype" in Google Search Console

About Contact Privacy policy Terms and conditions