PHP array whether there is a specified character and array length detection instance _php tutorial

Source: Internet
Author: User
This tutorial only tells two places one is to use the Array function In_array to check the array for the existence of the specified string, and to use the Count function to determine the length of the array. Definition and usage

This tutorial only tells two places one is to use the Array function In_array to check the array for the existence of the specified string, and to use the Count function to determine the length of the array.
Definition and usage
The In_array () function searches the array for the given value.

Grammar
In_array (Value,array,type)
*/

$os _list=array ("Mac", "NT", "Irix", "Linux");//define Arrays
if (In_array ("Irix", $os _list))//Check the array for presence Lrix
{
echo "Lrix exists in current operating system list"; If present, the output content
}
echo "
";
if (!in_array ("Mac", $os _list))
{
echo "Mac does not exist in the current operating system list"; Case sensitive so the sentence will not be executed
}


/*
In_array returns True if the given value exists in an array of arrays. If the third argument is set to True, the function returns true only if the element exists in the array and the data type is the same as the given value.

If no arguments are found in the array, the function returns FALSE.

Note: If the value parameter is a string and the type parameter is set to True, the search is case-sensitive.


Definition and usage

Grammar
Count (Array,mode)


The count () function calculates the number of cells in an array or the number of properties in an object.

For an array, returns the number of its elements, and returns 1 for other values. Returns 0 if the argument is a variable and the variable is not defined. If mode is set to Count_recursive (or 1), the number of elements in the array in the multidimensional array is recursively computed.

Array length
*/

$a [0]=1;//By assigning values separately, creating an array $a[]
$a [1]=3;
$a [2]=5;
$result =count ($a); Returns the number of elements in array $ A 3
echo $result;
echo "
";
$b [0]=7;
$b [5]=9;
$b [10]=11;
$result =count ($b); Returns the number of elements in an array $b 3
echo $result;
echo "
";
$result =count (NULL); Returns 0
echo $result;
echo "
";
$result =count (FALSE); Returns 1
echo $result;


/*
Hints and Notes
Note: When the variable is not set, or the variable contains an empty array, the function returns 0. You can use the Isset () variable to test whether a variable is set.


http://www.bkjia.com/PHPjc/445390.html www.bkjia.com true http://www.bkjia.com/PHPjc/445390.html techarticle This tutorial only tells two places one is to use the Array function In_array to check the array for the existence of the specified string, and to use the Count function to determine the length of the array. Define and use this tutorial only ...

  • 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.