【问题标题】:indexof array js equivalent in php [duplicate]php中等效的indexof数组js [重复]
【发布时间】:2023-03-31 06:15:02
【问题描述】:
$solutionsMap = [];
$score = 655536;

在 js 中我有 if(solutionsMap.indexOf(score) === -1).

我需要 php 中的 solutionsMap.indexOf(score) === -1 等价物。我尝试了array_search()、strpos(),但出现了错误。

我在这个问题之前搜索过,但仍然有错误。

【问题讨论】:

    标签: javascript php indexof


    【解决方案1】:

    使用array_search()函数:

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

    例如:

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

    输出:

    655536
    

    试试here

    【讨论】:

    • 这不起作用...
    • 它有效...在$key = array_search('score', $solutionsMap); // $key = 655536; 之前附加一个回声以打印结果...查看我的编辑。如果它不适用于您的代码,请发布您的整个代码
    • 你测试你的代码了吗?您的数组未正确定义..您切换键/值
    • 肯定 -_- eval.in/942351
    • 谁对我投了反对票?为什么?
    猜你喜欢
    • 2021-12-16
    • 1970-01-01
    • 2012-09-29
    • 2021-12-02
    • 2016-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多