• 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

woocommerce_wp_select options array from product attribute terms

How can I stop a symfony process which is listening on http://127.0.0.1:8000

Store multiple fields in JSON column (Nova CMS)

Need to display only array value in JSON output

How to validate Envato Purchase Code in PHP

Losing session data after POST from third party website

How to increase the PHP upload limits [duplicate]

Woocommerce redirect after add-to-cart error

How to use React Router with Laravel?

Substitute integers and dots with regex [duplicate]

Uploading video to Youtube using Youtube Data API V3 and Google API Client PHP -- getting 401 (unauthorized) message

Statement that checks whether a URL contains a particular path?

how to retrieve the first and last instance of a row in pdo dataset

phpunit - testing is painfully slow

loop through an anchor id

About Contact Privacy policy Terms and conditions