脱机和在线服务器进程的代码不同

时间:2013-06-20 13:17:06

标签: php arrays

我有一段代码可以在我的本地主机和实时服务器上进行不同的处理。

我不知道为什么或要改变什么。

这是一段代码:

for($k = 0; $k < count($data['SurveyAnswer']); $k++) {
    if(isset($data['SurveyAnswer'][$k]['answer']['number'])) {
        if($data['SurveyAnswer'][$k]['answer']['number'] != '')
            $data['SurveyAnswer'][$k]['answer'] = $data['SurveyAnswer'][$k]['answer']['number'].','.$data['SurveyAnswer'][$k]['answer']['text'];
        else
            $data['SurveyAnswer'][$k]['answer'] = '';
        } else if(isset($data['SurveyAnswer'][$k]['answer']['yn'])) {
    if($data['SurveyAnswer'][$k]['answer']['yn'] == 'No')
        $data['SurveyAnswer'][$k]['answer'] = 'No,' . $data['SurveyAnswer'][$k]['answer']['text'];
    else
        $data['SurveyAnswer'][$k]['answer'] = 'Yes';
    } else if(isset($data['SurveyAnswer'][$k]['answer']['scale'])) {
        $data['SurveyAnswer'][$k]['answer'] = $data['SurveyAnswer'][$k]['answer']['scale'] . ',' . $data['SurveyAnswer'][$k]['answer']['text'];
    }
}

为了论证,这是数据:

data = array(
    'SurveyAnswer' => array(
        0 => array (
            'answer' => array(
                'number' => '4',
                'text' => 'Test text'
            ),
        1 => array (
            'answer' => array(
                'number' => '',
                'text' => ''
            ),
        2 => array (
            'answer' => array(
                'yn' => 'No',
                'text' => 'Test text'
            ),
        3 => array (
            'answer' => array(
                'yn' => 'Yes',
                'text' => ''
            ),
        4 => array (
            'answer' => array(
                'scale' => 'Good',
                'text' => 'Testing text'
            )
        ),
        5 => array (
            'answer' => '3'
        )
    )
);

这是我的 localhost 更改数据的方式(Windows上的PHP版本5.4.7):

data = array(
    'SurveyAnswer' => array(
        0 => array (
            'answer' => '4,Test text'
            ),
        1 => array (
            'answer' => ''
            ),
        2 => array (
            'answer' => 'No,Test text'
            ),
        3 => array (
            'answer' => 'Yes'
            ),
        4 => array (
            'answer' => 'Good,Testing text'
            )
        ),
        5 => array (
            'answer' => '3'
        )
    )
);

这就是我的实时服务器更改数据的方式(CentOS上的PHP版本5.3.23):

data = array(
    'SurveyAnswer' => array(
        0 => array (
            'answer' => '4,4'
            ),
        1 => array (
            'answer' => ''
            ),
        2 => array (
            'answer' => 'T,T'
            ),
        3 => array (
            'answer' => 'Yes'
            ),
        4 => array (
            'answer' => 'T,T'
            )
        ),
        5 => array (
            'answer' => '3'
        )
    )
);

可能是导致问题的版本差异还是还有别的东西。

更新

真实世界数据,之前使用CakePHP调试和CakePHP调试代码:

本地主机

\app\Controller\SurveyAnswersController.php (line 51) (BEFORE)
array(
    'SurveyAnswer' => array(
        (int) 0 => array(
            'answer' => '1'
        ),
        (int) 1 => array(
            'answer' => '2'
        ),
        (int) 2 => array(
            'answer' => '3'
        ),
        (int) 3 => array(
            'answer' => array(
                'number' => '3',
                'text' => 'asdfasdfasdf'
            )
        )
    )
)

\app\Controller\SurveyAnswersController.php (line 67) (AFTER)
array(
    'SurveyAnswer' => array(
        (int) 0 => array(
            'answer' => '1'
        ),
        (int) 1 => array(
            'answer' => '2'
        ),
        (int) 2 => array(
            'answer' => '3'
        ),
        (int) 3 => array(
            'answer' => '3,asdfasdfasdf'
        )
    )
)

网络服务器

/app/Controller/SurveyAnswersController.php (line 51) (BEFORE)
array(
    'SurveyAnswer' => array(
        (int) 0 => array(
            'answer' => '1'
        ),
        (int) 1 => array(
            'answer' => '2'
        ),
        (int) 2 => array(
            'answer' => '3'
        ),
        (int) 3 => array(
            'answer' => array(
                'number' => '3',
                'text' => 'asdfasdfasdf'
            )
        )
    )
)

app/Controller/SurveyAnswersController.php (line 67) (AFTER)
array(
    'SurveyAnswer' => array(
        (int) 0 => array(
            'answer' => '1,1'
        ),
        (int) 1 => array(
            'answer' => '2,2'
        ),
        (int) 2 => array(
            'answer' => '3,3'
        ),
        (int) 3 => array(
            'answer' => '3,asdfasdfasdf'
        ),
    )
)

我将数据缩短为100左右。

1 个答案:

答案 0 :(得分:0)

信不信由你,但这是一个版本问题。将我的PHP更新到5.4.x并且它有效。