How to match the array and string? -Php Tutorial

Source: Internet
Author: User
How to match the array and string?
$ A = 'abc123'; // How does the string match the following array? Array ([0] => abc123 [1] => 1231231 [2] => 123123123 [3] => 222aads2 [4] => 23232 [8] => 222211 [9] => asfds) uppercase and lowercase letters before and after the number must be matched. if one of them is matched, true is returned. otherwise, false is returned.


Reply to discussion (solution)

Match refers to in the array?
In_array ()?

$ A = 'abc123'; $ arr = Array (0 => 'abc123', 1 => '20180101', 2 => '20180101', 3 => '222aads2 ', 4 => '20140901', 8 => '20160901', 9 => 'asfds '); if (in_array ($ a, $ arr )) {echo 'matched successfully';} else {echo 'matched failed ';}

$ A = 'abc123'; $ arr = Array (0 => 'abc123', 1 => '20180101', 2 => '20180101', 3 => '222aads2 ', 4 => '20140901', 8 => '20160901', 9 => 'asfds '); if (in_array ($ a, $ arr )) {echo 'matched successfully';} else {echo 'matched failed ';}


It means you forget in_array. at half past one, you will not be able to remember it.

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.