Schedule A Consultation

    Fields marked * are mandatory

      CA INQUIRY

      Continue : Latest php version (7.3) New Features

      This entry was posted on Friday November 22, 2019

      is_countable

      A countable component in your code can be a variable with an exhibit design or an item whose class is executing the countable interface. 

      A year ago, PHP 7.2 included an admonition that shows up at whatever point a designer was checking or attempting to circle an uncountable component.

      It is possible to solve this problem and one of the best solutions currently used is to apply a check like a snippet below:

      if (is_array($santa) || $santa instanceof Countable) {

          // $santa is countable

      }

      The code checks whether the variable is an array or is an instance of the Countable interface.

      Furthermore, it will work yet it appears to be somewhat “swarmed” and, the same number of you that work extended periods of time, sooner or later observing these sorts of lines destroys your eyes. 

       

      The group that is building up the new form assessed this and included another capacity that will help the web designer monstrously. 

       

      The is_countable capacity accepts a variable as a parameter and afterward returns a boolean in the event that the capacity is countable or not. 

       

      There is no limitation about the organization the parameter must be, obviously, on the off chance that you put a non-countable variable the arrival will be bogus.

      Let’s see it in practice:

      if (is_countable($santa)) {

          // $santa is countable

      }

      This snippet basically does the same thing as the previous one but is much easier to remember and, most importantly for me, more readable.

      Not to mention you can use this function as shown or in a ternary conditional operator which will look even more satisfying.

      For more information about is_countable have a look at the official RFC

       

      Read More….