• 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

How to get the survey List from surveygizmo API in the Postman?(Trial Version)

How to programmatically find public properties of a class from inside one of it's methods

Render the content of default_filter.php in Joomla front-end

Display the default discounted price and percentage on Woocommerce products

browsersync doesn't work with XAMPP

PHP block shortcut in Visual Studio Code

how to remove white space in select 2

How to skip cart page on woocomerce for certain products only?

Symfony autowiring issues since docker update

how to hide previous markers when new markers added in google map javascript api

RabbitMQ PRECONDITION_FAILED - unknown delivery tag

How to break out of a foreach once a condition is met?

Use same method for inertia response and json response Laravel Jetstream

How to loop sql table data inside a html table

I want to use codeigniter foreign character library in my custom PHP project how i can use it?

About Contact Privacy policy Terms and conditions