从一个数组中获取具有相同键的数组值,并将这些值存储在另一个数组中

时间:2014-04-09 07:17:24

标签: php

我正在开发一个php项目。我被困在这一点上。

这是我拥有的数组。

[text_numeric] => Array
    (
        [text] => Numeric field fillable by user
        [parameters] => Array
            (
                [prefix] => 1
                [price] => 1
                [sku] => 
                [quantity] => 
                [weight] => 
                [min_value] => 1
                [max_value] => 1
            )

        [operand] => Array
            (
                [op_fix_discount] => 1
                [op_fix_recharge] => 1
                [op_per_unit] => 1
                [op_percentage] => 
            )

    )

[checkbox] => Array
    (
        [text] => Checkbox attributes
        [parameters] => Array
            (
                [prefix] => 1
                [price] => 1
                [sku] => 1
                [quantity] => 1
                [weight] => 1
                [min_value] => 
                [max_value] => 
            )

        [operand] => Array
            (
                [op_fix_discount] => 1
                [op_fix_recharge] => 1
                [op_per_unit] => 
                [op_percentage] => 1
            )

    )

我想从另一个数组中获取此数组中的键值“text”的所有值。 像这样:

Array
(
    [0]=>Numeric field fillable by user
    [1]=>Checkbox attributes
)

1 个答案:

答案 0 :(得分:3)

如果你向我们展示了你为实现这一目标所做的努力,那可能会很棒。但是因为你是新来的,所以是codez。您只需使用foreach loop

即可获得
$new_array = array();
foreach($your_array as $k=>$row){
   $new_array[$k] = $row['text'];
}
print_r($new_array);

您也可以使用array_map

function getTextField($a) {
    return $a['text'];
}
$texts = array_map('getTextField', $your_array);
print_r($texts);