我有这个多维数组,我需要更改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
)
)
答案 0 :(得分:0)
foreach ($array as $key => $value) {
if ($key == 'parc' && $value == 100) {
$array['type'] = 'something new';
}
}
类似的东西?
答案 1 :(得分: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]';
}
});