PHP array problem array

Source: Internet
Author: User
PHP array problem array
$ Id = array ('AAA', 'BBB'); // This array can be used properly. If (in_array ($ url, $ id) // you can determine whether it is normal. // However, my current array is uncertain, not necessarily "aaa", "bbb ", $ idtxt = "'AAA', 'BBB, 'CCC '" will be added with the addition of another function $ idtxt. // it will be added frequently here, how can I write the following array to call this? $ Id = array ($ idtxt); // for example, if I write like this, the following judgment is not normal. how can I write it ?? If (in_array ($ url, $ id) // The result is not true.


What should I do ??


Reply to discussion (solution)

First, you violate the rules!
$ Id = array ('AAA', 'BBB ');
If (in_array ($ url, $ id ))
This is correct.

$ Id [] = 'CCC ';
If (in_array ($ url, $ id ))
This is still true.

While
$ Idtxt = "'AAA', 'BBB ', 'CCC '";
$ Vip = array ($ idtxt );
You can print out $ vip to find out why it is wrong.

First, you violate the rules!
$ Id = array ('AAA', 'BBB ');
If (in_array ($ url, $ id ))
This is correct.

$ Id [] = 'CCC ';
If (in_array ($ url, $ id ))
This is still true.

While
$ Idtxt = "'AAA', 'BBB ', 'CCC '";
$ Vip = array ($ idtxt );
You can print out $ vip to find out why it is wrong.

Well .. I know it is wrong... I mean, I wrote an error, but how can I write it to achieve what I want...

Format: $ id [] = 'CCC ';

$ Id = split (',', $ idtxt );

$ Id = split (',', $ idtxt );


$ Id = split (',', $ idtxt );
Print_r ($ vip); // This is the case. it is correct when $ id is output, but the following statements are still not normal. do you need to write other statements?
If (in_array ($ url, $ id ))

$ Id = split (',', $ idtxt );

Yes .. Wrong .. Thank you.

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.