<tfoot id='I4Cix'></tfoot>
  1. <legend id='I4Cix'><style id='I4Cix'><dir id='I4Cix'><q id='I4Cix'></q></dir></style></legend>
      <bdo id='I4Cix'></bdo><ul id='I4Cix'></ul>
  2. <small id='I4Cix'></small><noframes id='I4Cix'>

      <i id='I4Cix'><tr id='I4Cix'><dt id='I4Cix'><q id='I4Cix'><span id='I4Cix'><b id='I4Cix'><form id='I4Cix'><ins id='I4Cix'></ins><ul id='I4Cix'></ul><sub id='I4Cix'></sub></form><legend id='I4Cix'></legend><bdo id='I4Cix'><pre id='I4Cix'><center id='I4Cix'></center></pre></bdo></b><th id='I4Cix'></th></span></q></dt></tr></i><div id='I4Cix'><tfoot id='I4Cix'></tfoot><dl id='I4Cix'><fieldset id='I4Cix'></fieldset></dl></div>
    1. PHP Count 布尔数组中真值的数量

      PHP Count Number of True Values in a Boolean Array(PHP Count 布尔数组中真值的数量)
      <tfoot id='yJPnY'></tfoot>

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

          <legend id='yJPnY'><style id='yJPnY'><dir id='yJPnY'><q id='yJPnY'></q></dir></style></legend>

              <tbody id='yJPnY'></tbody>

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

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

              • 本文介绍了PHP Count 布尔数组中真值的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个关联数组,我需要在其中计算布尔真值的数量.

                I have an associative array in which I need to count the number of boolean true values within.

                最终结果是创建一个 if 语句,当数组中只存在一个真值时,该语句将返回真值.如果数组中有多个真值,或者数组中没有真值,则需要返回 false.

                The end result is to create an if statement in which would return true when only one true value exists within the array. It would need to return false if there are more then one true values within the array, or if there are no true values within the array.

                我知道最好的方法是以某种形式使用 count 和 in_array .我不确定这是否可行,只是在我的头顶上,但即使可行,这是最好的方法吗?

                I know the best route would be to use count and in_array in some form. I'm not sure this would work, just off the top of my head but even if it does, is this the best way?

                $array(a->true,b->false,c->true)    
                
                if (count(in_array(true,$array,true)) == 1)
                {
                    return true
                }
                else
                {
                    return false
                }
                

                推荐答案

                我会使用 array_filter.

                I would use array_filter.

                $array = array(true, true, false, false);
                echo count(array_filter($array));
                //outputs: 2
                

                http://codepad.viper-7.com/ntmPVY

                Array_filter 将删除 false-y (value == false) 的值.那就来数一数吧.如果您需要根据某些特殊值进行过滤,例如您正在查找特定值,则 array_filter 接受一个可选的第二个参数,该参数是您可以定义的函数,用于返回值是 true(未过滤)还是 false(过滤掉)).

                Array_filter will remove values that are false-y (value == false). Then just get a count. If you need to filter based on some special value, like if you are looking for a specific value, array_filter accepts an optional second parameter that is a function you can define to return whether a value is true (not filtered) or false (filtered out).

                这篇关于PHP Count 布尔数组中真值的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 的问题)

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

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

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