我想知道如何在数组项中爆炸值,例如,
这是从表单发送的$ _POST数据
[required] => Array
(
[0] => member_email
[1] => member_birthday member_secret
)
我用来将required
值拆分为数组的脚本
# Set the required array.
$items_variable = array(
'required'
);
# Loop the array.
foreach($items_variable as $item_variable)
{
# Set the main variables.
$$item_variable = set_variable($_POST,$item_variable);
}
# Get the required field and put them in an array.
$array_required = is_array($required)? $required : explode(' ',$required);
print_r($array_required);
结果,
Array
(
[0] => member_email
[1] => member_birthday member_secret
)
但这是我追求的正确结果,
Array
(
[0] => member_email
[1] => member_birthday
[2] => member_secret
)
有什么想法吗?
答案 0 :(得分:0)
$required = array();
foreach( $_POST['required'] AS $val )
$required = $required + explode(' ', $val); // '+' means union in this case