Php to determine whether the program is an array code _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php determines whether it is an array program code. In php, it is very easy to determine whether the variable is an array. Using the is_array () function in php can quickly determine whether the variable is an array. I will introduce it to you below. Is_array: it is very easy to check whether the variable is an array in php. Using the is_array () function in php, you can quickly determine whether the variable is an array. I will introduce it to you below.

Is_array-check whether the variable is an array

Report a bug description
Bool is_array (mixed $ var)

If var is array, TRUE is returned; otherwise, FALSE is returned.

Example

The code is as follows:

$ A = 1;

If (is_array ($ ))
{
Echo 'is an array ';
}
Else
{
Echo 'not array 0 ';
}

Example

The code is as follows:

Function is_vector (& $ array ){
If (! Is_array ($ array) | empty ($ array )){
Return-1;
}
$ Next = 0;
Foreach ($ array as $ k => $ v ){
If ($ k! ==$ Next) return false;
$ Next ++;
}
Return true;
}
?>

Method for determining whether to index an array

Echo is_assoc ($ array )? 'Index array': 'not an index array ';

The code is as follows:

Function is_assoc ($ array ){
If (is_array ($ array )){
$ Keys = array_keys ($ array );
Return $ keys! = Array_keys ($ keys );
}
Return false;
}


The evaluate () function can quickly determine whether the variable is an array. I will introduce it to you below. Is_array checks whether the variable is a number...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.