• 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

Symfony 4: how to allow dynamic values for array nodes in bundle configuration?

VB.NET WebRequest with PHP POST

PHP array sort and remove duplicates by two field values

php file upload scanning using clamav, permissions on /tmp/

enable Apache http Authorization header

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

Star and Half Star Rating in Laravel

Split a string array into pieces

PHP: remove filename from path

Woocommerce Edit Message "An account is already registered with your email address. Please log in."

I need to link Google Sheet with my Laravel

Upgrade PHP on AWS Linux

Laravel insert dynamic input values with radio button

How to get company posts from LinkedIn via API?

Autoloading classes in PHPUnit using Composer and autoload.php

About Contact Privacy policy Terms and conditions