Change value in array key that has a specific sub key value in php -


what shortest way change multiple values in array key has specific value in it?

for example, have array:

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"   } } 

and want change "state" value of key has "34879205" value "keystring" sub-key.

you can use foreach():-

foreach($array &$value) {     if ($value['keystring'] == '34879205'){         $value['state'] = "";//change value here     } } 

output:- https://eval.in/838789


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -