dongnaigu2052 2018-01-26 08:50
浏览 69

indexof数组js等效于php [duplicate]

This question already has an answer here:

$solutionsMap = [];
$score = 655536;

in js I have if(solutionsMap.indexOf(score) === -1).

I need an equivalent in php for solutionsMap.indexOf(score) === -1. I tried array_search(), strpos(), but with errors.

I searched before this question, but I still got errors.

</div>
  • 写回答

2条回答 默认 最新

  • dongpao2871 2018-01-26 08:53
    关注

    Use the array_search() function:

    $k = array_search('text', $array);
    

    For example:

    $solutionsMap = array('655536' => 'score', 1 => 'other');
    
    $key = array_search('score', $solutionsMap); // $key = 655536;
    
    echo $key;
    

    Output:

    655536
    

    Try it here.

    评论

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?