当前位置:Gxlcms > PHP教程 > php数组函数in_array()查找数组中是否存在指定值

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

时间:2021-07-01 10:21:17 帮助过:17人阅读

  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

人气教程排行