The value assignment of the in_array variable is treated as a value. Solution

Source: Internet
Author: User
The value assignment of the in_array variable is treated as a value. The value assignment of the in_array variable is treated as a value. for the solution, see the following code: & lt ;? Php // $ meb ['learned'] The database value is dance, street dance, host, instructor $ learn & nbsp ;=& nbsp; explode (',', $ meb ['learned'] the value assignment of the in_array variable is treated as a value. Solution
The value assignment of the in_array variable is treated as a value. Solution
For details, see the following code:

// $ Meb ['learned'] database values: dance, street dance, host, lecturer
$ Learn = explode (',', $ meb ['learned']);
// Echo $ learn [0]. $ learn [1]. $ learn [2]. $ learn [3]. $ learn [4]. $ learn [5];
$ Strp = str_replace (',', '","', $ meb ['learned']);
$ Strp2 = '"'. $ strp .'"';
$ People = array ($ strp2 );
Print_r ($ people );
// The output result is Array ([0] => "dance", "street dance", "host", "lecturer ")
If (in_array ('lecturer ', $ people )){
Echo "Match found ";
}
Else
{
Echo "Match not found ";
}
?>

The output of in_array's judgment result is "Match not found", that is, the lecturer is not included in $ people, probably because it is regarded as a whole. How to optimize the specific solution and code
Share:
------ Solution --------------------
$ Learn = explode (',', $ meb ['learned']);
$ Learn is not the array you need

If (in_array ('lecturer ', $ learn )){
Echo "Match found ";
}
Else
{
Echo "Match not found ";
}

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.