如何爆炸数组项内的值?

时间:2012-02-10 19:46:57

标签: php multidimensional-array php-5.3

我想知道如何在数组项中爆炸值,例如,

这是从表单发送的$ _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
    )

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

$required = array();
foreach( $_POST['required'] AS $val )
  $required = $required + explode(' ', $val); // '+' means union in this case