php - 使用 in_array() 比较两个数组时出错

标签 php html mysql pdo

我有一个数组,其中包含我 friend 的所有详细信息(通过 MySQL select ALL),另一个数组则包含团队中所有人员的所有详细信息。现在,我想在 HTML 选择列表中显示我的所有 friend ,但我不希望已经属于“团队”的 friend 出现在选择列表中。

我尝试使用in_array(),但没有得到任何结果。我所有的 friend 仍然出现在选择列表中,尽管他们中的一些人已经是“团队”的一部分。

这是代码:

<form action="tmembers.php" method="post">    
    <select multiple="true" name="members[]"  val id="member" class="">    
        <?php
        while($record5 = $stmt5->fetch()){    
            $friends[] = $record5;      //array containing details of all friends
        }
        while($record6 = $stmt6->fetch()){   
            $membersarray[] = $record6;  //array containing details of team members
        }

        foreach ($friends AS $t) {
            if (in_array($t, $membersarray)) {
               continue;            
            } 
        ?>

        <option value="<?php echo $t['id'] ; ?>">  
            <?php echo $t['surname'];?> <?php echo $t['firstname'] ; ?>  
        </option>

        <?php } 
        ?>

        </select>
        </br>
        <input type="submit" value="Send Invite" name="invite" class=""/>
   </form> 

最佳答案

使用这个

for($i=0;$i<count($friends);$i++) {
    if (in_array($friends[$i], $membersarray)) {
       continue;            
    } 
}

关于php - 使用 in_array() 比较两个数组时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27462158/

相关文章:

php - 想要使用 php 显示各自父测试下的子测试

php - HTML/PHP/MYSQL - 如何使用 MYSQL 中的 2 个不同字段填充下拉列表

html - 纯 CSS - 多读/少读图像

mysql - React Native 获取 MYSQL 中的数据

php - CI 如何仅使用数据的最后 4 个字符进行 order_by

php - fatal error : Class 'WP_Customize_Control' not found - WordPress

html - 如何使用 css 集中列表?

php - 使用特定日期的 shell 命令从 SQL 转储数据库

mySQL 查询根据逗号分隔的列表值检查字符串

javascript - 我需要帮助使用 Ajax、PHP 和 mySQL 将信息发送到我的服务器而不使用表单