is_array

Is_array function returns Boolean value ( true of false ) based on the input data. It returns true if variable is an array. Here is an example
$a= array("Three", "two", "Four", "five","ten"); 
$b="Hello Welcome to plus2net ";
if(is_array($a)){ // Change this variable to $b
echo " This is an array ";
}else{
echo " This is not an array ";
}
The above code will return This is an array if $a is checked using if condition.

Example

<?Php
$str="Learn web programming at plus2net.com";
echo is_array($str) ? 'Yes, Array' : 'not an Array';
?>
Output is
not an Array
By using split function we can break a sting and create an array. Here is the modified code.
<?Php
$str=split(" ","Learn web programming at plus2net.com");
echo is_array($str) ? 'Yes, Array' : 'not an Array';
?>
Output is
Yes, Array

Example 1: Checking an Associative Array

<?php
$array = ['name' => 'John', 'age' => 25];
echo is_array($array) ? 'Yes, Array' : 'Not an Array';  // Output: Yes, Array
?>

Example 2: Using is_array() with Nested Arrays

<?php
$nestedArray = [1, [2, 3], 4];
echo is_array($nestedArray[1]) ? 'Nested is Array' : 'Nested is not an Array';  // Output: Nested is Array
?>

Example 3: Checking Non-Array Variables

<?php
$var = 'Hello';
echo is_array($var) ? 'Array' : 'Not an Array';  // Output: Not an Array
?>

Example 4: Using is_array() in Conditionals

<?php
$input = [10, 20, 30];
if (is_array($input)) {
    echo "The input is an array!";
} else {
    echo "The input is not an array!";
}
?>

Array REFERENCE in_array(): Searching Array
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer