<bdo id='jGLqy'></bdo><ul id='jGLqy'></ul>
    <legend id='jGLqy'><style id='jGLqy'><dir id='jGLqy'><q id='jGLqy'></q></dir></style></legend>

    <small id='jGLqy'></small><noframes id='jGLqy'>

  1. <i id='jGLqy'><tr id='jGLqy'><dt id='jGLqy'><q id='jGLqy'><span id='jGLqy'><b id='jGLqy'><form id='jGLqy'><ins id='jGLqy'></ins><ul id='jGLqy'></ul><sub id='jGLqy'></sub></form><legend id='jGLqy'></legend><bdo id='jGLqy'><pre id='jGLqy'><center id='jGLqy'></center></pre></bdo></b><th id='jGLqy'></th></span></q></dt></tr></i><div id='jGLqy'><tfoot id='jGLqy'></tfoot><dl id='jGLqy'><fieldset id='jGLqy'></fieldset></dl></div>
  2. <tfoot id='jGLqy'></tfoot>

      如何在 PHP 中搜索数组中的多个值?

      How to search Array for multiple values in PHP?(如何在 PHP 中搜索数组中的多个值?)
        <bdo id='MGJdm'></bdo><ul id='MGJdm'></ul>
      • <i id='MGJdm'><tr id='MGJdm'><dt id='MGJdm'><q id='MGJdm'><span id='MGJdm'><b id='MGJdm'><form id='MGJdm'><ins id='MGJdm'></ins><ul id='MGJdm'></ul><sub id='MGJdm'></sub></form><legend id='MGJdm'></legend><bdo id='MGJdm'><pre id='MGJdm'><center id='MGJdm'></center></pre></bdo></b><th id='MGJdm'></th></span></q></dt></tr></i><div id='MGJdm'><tfoot id='MGJdm'></tfoot><dl id='MGJdm'><fieldset id='MGJdm'></fieldset></dl></div>
            <tbody id='MGJdm'></tbody>

          <small id='MGJdm'></small><noframes id='MGJdm'>

        1. <legend id='MGJdm'><style id='MGJdm'><dir id='MGJdm'><q id='MGJdm'></q></dir></style></legend>
            <tfoot id='MGJdm'></tfoot>

                本文介绍了如何在 PHP 中搜索数组中的多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要从重复的值中获取键.我尝试使用 array_search 并且效果很好,但是我只得到了第一个值作为命中.

                I need to get the keys from values that are duplicates. I tried to use array_search and that worked fine, BUT I only got the first value as a hit.

                我需要从重复值中获取两个键,在本例中为 0 和 2.作为数组输出的搜索结果会很好.

                I need to get both keys from the duplicate values, in this case 0 and 2. The search result output as an array would be good.

                是否有一个 PHP 函数可以做到这一点,还是我需要编写一些多个循环来做到这一点?

                Is there a PHP function to do this or do I need to write some multiple loops to do it?

                $list[0][0] = "2009-09-09";
                $list[0][1] = "2009-05-05";
                $list[0][2] = "2009-09-09";
                $list[1][0] = "first-paid";
                $list[1][1] = "1";
                $list[1][2] = "last-unpaid";
                
                echo array_search("2009-09-09",$list[0]);
                

                推荐答案

                你想要 array_keys 与搜索值

                array_keys($list[0], "2009-09-09");
                

                这将返回具有指定值的键数组,在您的情况下为 [0, 2].如果你也想找到重复的,你可以先通过 array_unique,然后在原始数组上使用 array_keys 迭代该数组;返回长度大于 1 的数组的任何内容都是重复的,结果是存储重复项的键.比如……

                which will return an array of the keys with the specified value, in your case [0, 2]. If you want to find the duplicates as well, you can first make a pass with array_unique, then iterate over that array using array_keys on the original; anything which returns an array of length > 1 is a duplicate, and the result is the keys in which the duplicates are stored. Something like...

                $uniqueKeys = array_unique($list[0])
                
                foreach ($uniqueKeys as $uniqueKey)
                {
                  $v = array_keys($list[0], $uniqueKey);
                
                  if (count($v) > 1)
                  {
                    foreach ($v as $key)
                    {
                      // Work with $list[0][$key]
                    }
                
                  }
                }
                

                这篇关于如何在 PHP 中搜索数组中的多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                        <small id='RjdJT'></small><noframes id='RjdJT'>

                          <tbody id='RjdJT'></tbody>

                          <bdo id='RjdJT'></bdo><ul id='RjdJT'></ul>

                          <legend id='RjdJT'><style id='RjdJT'><dir id='RjdJT'><q id='RjdJT'></q></dir></style></legend><tfoot id='RjdJT'></tfoot>

                          <i id='RjdJT'><tr id='RjdJT'><dt id='RjdJT'><q id='RjdJT'><span id='RjdJT'><b id='RjdJT'><form id='RjdJT'><ins id='RjdJT'></ins><ul id='RjdJT'></ul><sub id='RjdJT'></sub></form><legend id='RjdJT'></legend><bdo id='RjdJT'><pre id='RjdJT'><center id='RjdJT'></center></pre></bdo></b><th id='RjdJT'></th></span></q></dt></tr></i><div id='RjdJT'><tfoot id='RjdJT'></tfoot><dl id='RjdJT'><fieldset id='RjdJT'></fieldset></dl></div>