How to check a variable is an array or not in PHP ? Last Updated : 22 Oct, 2021 Comments Improve Suggest changes Like Article Like Report There are two ways for checking whether the variable is an array or not. We can check whether a variable is an array or not by using the PHP is_array() function and by casting the variable to the array. Approach 1: We can check whether a variable is an array or not using the is_array() function. The PHP is_array() function is a variable handling function that checks whether a variable is an array or not. Syntax: is_array( $variable_name ); Parameter: It accepts a single parameter. This parameter must be the variable name for which the check is done if it is an array or not. Return value: It returns true if the boolean value is TRUE else false. Example 1: The is_array() function returns true(1) when passed parameter is array else it will return false (nothing). PHP <?php $isArr = "friends"; if(is_array($isArr)) { echo "Array"; } else { echo "Not an Array"; } echo "<br>"; $isArr = array("smith", "john", "josh"); if(is_array($isArr)) { echo "Array"; } else { echo "Not an Array"; } ?> OutputNot an Array<br>Array Approach 2: By casting the variable to an array. We have to cast the variable to an array that we want to check. For Array: type casted array === original array Original array:john, johnson, steveType casted array:john, johnson, steve For normal variable: type casted array != original array Original variable:friends Type casted variable:friends, , Example 2: After typecasting, an index-based array will be formed. PHP <?php $isArr = array("john", "johnson", "steve"); if((array)$isArr === $isArr) { echo "It is an Array\n"; } else { echo "It is not an Array\n"; } $isArr = "friends"; if((array)$isArr === $isArr) { echo "It is an Array"; } else { echo "It is not an Array"; } ?> OutputIt is an Array It is not an Array Comment More infoAdvertise with us Next Article How to check a variable is an array or not in PHP ? N nachiketmh7 Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Questions Similar Reads How to Check an Array is Sorted or Not in PHP? Given an array, the task is to check whether the given array is sorted or not. Arrays are often used to store and manipulate data. One common task is to check if an array is sorted in ascending or descending order. This article will explore different approaches to determine whether an array is sorte 3 min read How to Check if a Variable is an Array in JavaScript? To check if a variable is an array, we can use the JavaScript isArray() method. It is a very basic method to check a variable is an array or not. Checking if a variable is an array in JavaScript is essential for accurately handling data, as arrays have unique behaviors and methods. Using JavaScript 2 min read How to check an element is exists in array or not in PHP ? An array may contain elements belonging to different data types, integer, character, or logical type. The values can then be inspected in the array using various in-built methods : Approach 1 (Using in_array() method): The array() method can be used to declare an array. The in_array() method in PHP 2 min read How to Check Whether a Variable is Empty in PHP? Given some values of variables, the task is to check whether the variable is empty or not in PHP. An empty variable can refer to a variable that has not been set, a variable that has been explicitly set to an empty value, or a variable that contains a value that is considered empty. In this article, 5 min read How to check an array is empty or not using jQuery ? In this article, we will check if an array is empty or not using jQuery. In JavaScript, arrays are a special type of object. If we use the typeof operator for arrays, it returns "object". We can use jQuery's isEmptyObject() method to check whether the array is empty or contains elements. The isEmpty 2 min read Like