首页  >  文章  >  后端开发  >  php数组函数 in_array() 查找数组中是否存在指定值

php数组函数 in_array() 查找数组中是否存在指定值

WBOY
WBOY原创
2016-07-25 09:04:50892浏览
  1. $people = array("Peter", "Joe", "Glenn", "Cleveland");

  2. if (in_array("Glenn",$people))

  3. {
  4. echo "Match found";
  5. }
  6. else
  7. {
  8. echo "Match not found";
  9. }
  10. ?>
复制代码

输出: Match found

例2:

  1. $people = array("Peter", "Joe", "Glenn", "Cleveland", 23);

  2. if (in_array("23",$people, TRUE))

  3. {
  4. echo "Match found
    ";
  5. }
  6. else
  7. {
  8. echo "Match not found
    ";
  9. }if (in_array("Glenn",$people, TRUE))
  10. {
  11. echo "Match found
    ";
  12. }
  13. else
  14. {
  15. echo "Match not found
    ";
  16. }if (in_array(23,$people, TRUE))
  17. {
  18. echo "Match found
    ";
  19. }
  20. else
  21. {
  22. echo "Match not found
    ";
  23. }
  24. ?>
复制代码

输出: Match not found Match found Match found



声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn