更改数组键中具有特定值的多个值的最短方法是什么?
例如,我有这个数组:
array(2) {
[0]=>
array(5) {
["state"]=>
string(6) "active"
["payer_mail"]=>
string(12) "mail@none.com"
["start"]=>
string(12) "06/05/2015"
["end"]=>
string(8) "08/07/2017"
["price"]=>
string(8) "45.00"
["keystring"]=>
string(8) "493457025"
}
[1]=>
array(6) {
["place"]=>
string(2) "47"
["state"]=>
string(8) "canceled"
["payer_mail"]=>
string(12) "mail@none.com"
["start"]=>
string(9) "20/8/2014"
["end"]=>
string(10) "20/10/2017"
["price"]=>
string(5) "95.00"
["keystring"]=>
string(8) "34879205"
}
}
而且我想更改其“ keystring”子键具有“ 34879205”值的键的“ state”值.
解决方法:
您可以使用foreach():-
foreach($array as &$value) {
if ($value['keystring'] == '34879205'){
$value['state'] = "";//change value here
}
}
标签:arrays,php
来源: https://codeday.me/bug/20191025/1931527.html