dsam70528 2013-01-10 00:06
浏览 79
已采纳

当有多种可能性时,查找数组中对象的索引

I have an array, and I want to find all of the indexes of a certain object in the array. When I use array_search, it only returns the first index in which the object can be found.

echo array_search(3, array(3, 3, 4));

This returns 0, but I want to know that both indexes 0 and 1 have the integer 3 as their object. Is there a way of doing this without using a for loop?

  • 写回答

2条回答 默认 最新

  • dongqiao1158 2013-01-10 00:09
    关注

    Try array_keys() method :

      $array = array(3, 3, 4);
      print_r(array_keys($array, "3"));
    

    For reference:

    array_keys() — Return all the keys or a subset of the keys of an array Info & usuage examples : http://php.net/manual/en/function.array-keys.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!