• 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

Laravel Pagination links() not working

possible options to create pdf file using html elements to generate invoice in php and codeigniter

Artisan, creating tables in database

Laravel Database Strict Mode

Timber: Single post pagination does not work (wp_link_pages)

XSS attack still works despite htmlspecialchars() doing its work

Hide email address with stars (*)

How to fix Call to undefined method AppModelsTableName::factory?

How to insert Google Adsense Code in PHP script?

Laravel Carbon throws error The format separator does not match

Best way to scrolldown onpageload

How can i call a function that executes an fpdf based on the choice of a form selector?

Check If array is null or not in php

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource [duplicate]

Unable to run composer install

About Contact Privacy policy Terms and conditions