How to check if an array contains at least 1 element (and not just an empty array $myarray = array(); )?
$myarray = array();
Is there any way?
eg.
if ($myarray) { } if (count($myarray)) { } if (count($myarray) > 0) { }
Or is there a wrong way?
For at least 1 element, this will be:
if (!empty($myarray)) {}
Perhaps check for non-emptyness via empty() ?
empty()
The following things are considered empty:"(empty line)0 (0 as an integer)0.0 (0 as a float)"0" (0 as a string)NullFalsearray () (empty array)var $ var; (declared variable, but no value in the class)
The following things are considered empty:
if (!empty($myarray)) { // }
But I'm not sure if there is one canonical way to do this; php can follow TMTOWTDI .
I believe if(!empty($myarray)) works too. This means that you will not run w / e if you get array([0] => '')
if(!empty($myarray))
array([0] => '')
Source: https://habr.com/ru/post/905953/More articles:Can .NET be parsed and evaluated at runtime - c #C ++ / opengl application runs smoothly with a debugger application - c ++Does tryhaskell.org support definitions? - haskellHow to return failure details from a method without using exceptions and optionally include a value? - javato create a C # project at runtime - c #Why doesn't ICS come with some icons for Holo Light? - androidRun .NET code at runtime - .netA grid with SharedSizeGroup columns acts very strange (* NOT * an infinite loop) - performanceVisual Studio Intellisense for Backbone.js - javascriptWhat does ccp mean in Cocos2d / Objective-C? - objective-cAll Articles