Php array_search () to delete array values

Source: Internet
Author: User
Tags php tutorial

The array_search () function is the same as the in_array () function. You can find a key value in the array. If this value is found, the key name of the matching element is returned. If not found, false is returned.

If the third parameter strict is set to true, the key name of the corresponding element is returned only when the data type and value are consistent.

Array_search (value, array, strict)

Instance

The code is as follows: Copy code

<? Php Tutorial
$ A = array ("a" => "5", "B" => 5, "c" => "5 ");
Echo array_search (5, $ a, true );
?> Output:

B
Further, use it to delete array elements

The code is as follows: Copy code

$ Arr = Array ([0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day .);

If ($ key = array_search ('day', $ arr ))){

Unset ($ arr [$ key]);

}


Delete them and use other values instead.

 

The code is as follows: Copy code

If ($ key = array_search ('day', $ arr ))){

Array_splice ($ arr, $ key, 1 );

}

 

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.