Javatpoint Logo
Javatpoint Logo

Is_array() Function in PHP

Array - arrays is a specific data type that allows us to store numerous components of a single type of data under a specific variable, this method helps us to reduce the time and energy of creating several variables for every data. We can access every element of an array using an index, for example if we need to store the salaries of 5 different employees, instead of creating 5 variables for every employee we can easily create an array salary with the salaries of all employees inside a single variable salary. In this case creating 5 variables is still a doable task but what if we have to store the salary of 100 or even 1000 employees, in such cases arrays are the best preference.

Is _ array ( ) - is another inbuilt function of PHP which is used to evaluate whether a defined variable is an array or a different variable.

Syntax:

is_array function accepts a single parameter, $ variable name is the nave of the declared variable which we have to check. The is_array () function returns Boolean value i.e. if the variable is an array it will return TRUE else it will return FALSE.

Example

Output:

good morning is not an array
Array ( [0] => cyan [1] => magenta [2] => yellow ) is an array
Array ( [doctor] => 35LPA [engineer] => 27LPA [accountant] => 20LPA ) is an array
cyan, magenta, yellow is not an array

In this program, we have declared multiple variables with different data and with the if else statement we have deduced the output whether the declared variable contains an array or not, we have used is_array function to check whether the declared data is array or not.

Example:

Output:

Array ( [0] => A [1] => B [2] => C ) 
A B C is an array 

29.99 is not a array value. 

42 is not a array value. 

abc is not a array value.

In this program, we have declared multiple variables with different data and with the if else statement we have deduced the output whether the declared variable contains an array or not, we have used is_array function to check whether the declared data is array or not.


Next Topic#





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA