0

我有这个多维数组,type当我找到parc值时我需要更改字段,在这种情况下100,在这个数组中使用 php ......但我总是找到的所有东西都用最后一个数组替换了总数组。任何人都可以帮助我吗?非常感谢...对不起我的英语不好。

Array
(
    [1] => Array
        (
            [designacao] => 
            [imagem] => 
            [produto] => KITCHENAID Robot de cozinha Artisan 5KSM150PSETG cor-de-laranja
            [preco_t] => 710
            [t_parc] => Parcela 1
            [parc] => 100
            [symbol] => €
            [zona] => COZINHA
            [id] => 0
            [type] => checkbox
        )

    [2] => Array
        (
            [designacao] => 
            [imagem] => 
            [produto] => KITCHENAID Robot de cozinha Artisan 5KSM150PSETG cor-de-laranja
            [preco_t] => 710
            [t_parc] => Parcela 2
            [parc] => 100
            [symbol] => €
            [zona] => COZINHA
            [id] => 0
            [type] => checkbox
        )
)
4

2 回答 2

0
foreach ($array as $key => $value) {
    if ($key == 'parc' && $value == 100) {
        $array['type'] = 'something new';
    }
}

类似的东西?

于 2013-04-02T23:37:59.220 回答
0

试试这个:

$source = array(); // your array

$keyName = 'parc';
$keyValue = 100;
$keyToChange = 'type';

array_walk($source, function (&$element) use ($keyName, $keyValue, $keyToChange) {
    if (
        array_key_exists($keyName, $element)
        && $element[$keyName] === $keyValue
    ) {
        $element[$keyToChange] = '[do_something]';
    }
});
于 2013-04-02T23:48:26.010 回答