如何使$ _POST ['value']作为数字数组来做foreach

时间:2015-10-19 07:37:19

标签: php

我在这里有一个关于如何将public function handleProviderCallback() { $facebookData = Socialite::driver('facebook')->user(); // check if already in DB try{ $user = User::where('facebook_id', $data->id)->firstOrFail(); } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) { // create a new user $user = new User(); // set the properties you want // $user->facebook_id = $data->id; // ... // then save $user->save(); } // login the user Auth::login($user); // perhaps return a redirect response return redirect()->action('MyController@myAction'); } 从表单解析为$POST_['value'] (e.g 3785,3789,3790,3787 )并进行预测的问题。请参阅下面的示例代码:

array($POST_['value'])

然而结果显示为****整个字符串**而不是数组**。 如果我像这样放function someFunction(){ $html = ''; $int = $_POST['Ids']; //POST the value as 3785,3789,3790,3787 $IDs = array($int); foreach ($IDs as $ID) { $intVal = '<int>' . $ID .'</int>'; $html .= $intVal; } return $html; } ,它将在foreach中解析为数组。如何将array(3785,3789,3790,3787)转换为数字或某种排序以便被识别为数组?

谢谢

麦克

2 个答案:

答案 0 :(得分:1)

这将有效

function someFunction(){
    $html = '';
    $int = $_POST['Ids']; //POST the value as 3785,3789,3790,3787
    $IDs = explode(',', $_POST['Ids']);

    foreach ($IDs as $ID) {
        $intVal = '<int>' . $ID .'</int>';
        $html .= $intVal;
    }

    return $html;
}

答案 1 :(得分:0)

您需要快速修复以下行:

<?php

$IDs = explode(",", $int);