How To Test If a Variable Is an Array?

deepak singh
Posts: 686
Joined: Fri Sep 30, 2016 4:19 pm

How To Test If a Variable Is an Array?

Postby deepak singh » Sat Oct 01, 2016 5:17 pm

How To Test If a Variable Is an Array?

rameshkhd
Posts: 1279
Joined: Sun Aug 28, 2016 10:45 am

Re: How To Test If a Variable Is an Array?

Postby rameshkhd » Sat Oct 01, 2016 5:17 pm

Testing if a variable is an array is easy. Just use the is_array() function. Here is a PHP script on how to use is_array():
<?php
$var = array(0,0,7);
print("Test 1: ". is_array($var)."\n");
$var = array();
print("Test 2: ". is_array($var)."\n");
$var = 1800;
print("Test 3: ". is_array($var)."\n");
$var = true;
print("Test 4: ". is_array($var)."\n");
$var = null;
print("Test 5: ". is_array($var)."\n");
$var = "PHP";
print("Test 6: ". is_array($var)."\n");
print("\n");
?>
This script will print:
Test 1: 1
Test 2: 1
Test 3:
Test 4:
Test 5:
Test 6:


Return to “PHP”

Who is online

Users browsing this forum: No registered users and 4 guests