Php 数组\u搜索不工作(返回null)

Php 数组\u搜索不工作(返回null),php,cakephp,null,Php,Cakephp,Null,我正在使用CakePHP 我有$pinder和$number: $needle = 14; $numbers = Array ( [0] => 14 [1] => 15 [2] => 16 ) 我只是这样做: $n = array_search($needle,$numbers); 并且$n返回NULL 如果您想在这里获得所有代码的完整上下文,它是来自ajax调用的php: if(isset($_POST['numbers']))

我正在使用CakePHP

我有$pinder和$number:

$needle = 14;

$numbers =
Array
(
    [0] => 14 
    [1] => 15 
    [2] => 16 
)
我只是这样做:

$n = array_search($needle,$numbers);
并且$n返回NULL

如果您想在这里获得所有代码的完整上下文,它是来自ajax调用的php:

if(isset($_POST['numbers']))
        {
            $jobsX = $this->Job->find('all',array('conditions' => array('Job.owner' => $id)));

            $numbers = $_POST['numbers'];

            $n = 0;

            $this->autoRender = false;

            foreach($jobsX as $key => $jo)
            {       
                $needle = $jo['Job']['id'];

                $n = array_search($needle,$numbers);

                $jobsX[$key]['Job']['order'] = $n;
            }

            $this->Job->saveAll($jobsX);

            echo 1;
        }
对我来说没有意义

编辑:
如果你在外边做这件事就行了。。。但是为什么呢?

解决方案是使用intval:

$needle = intval($jo['Job']['id']);

我不明白,这在另一种情况下是不必要的…

你确定
$numbers
数组吗?我很怀疑。如果是的话,有什么意义?我甚至创建了一个个性化的函数,将一个值与数组中的每个元素进行比较,即使结果是相同的。。。我是说。。。它返回16与16不同!重点是什么?嗯
array\u search()
要求第二个参数是数组。因此,如果不传递数组,它将无法按预期工作。如果我在foreach之外使用它,并提供相同的参数,除了$pinder,我会输入一个数字…已解决。。。但这个解决方案对我来说毫无意义:使用intval$needle=intval($jo['Job']['id'])$指针为空。