3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array ( 'igive' => array ( 0 => array ( 'name' => 'Alex', 'shop_name' => 'Shop1', 'rights' => 'admin', 'who_use' => '', 'user_id' => '765754346', ), 1 => array ( 'name' => 'Dmitry', 'shop_name' => 'Shop2', 'rights' => 'manager', 'who_use' => '', 'user_id' => '123456789', ), ), 'giventome' => array ( ), ); /*How can i set value (1, for example) for a key 'who_use' where 'user_id' = 765754346?*/ $user_id = '765754346'; array_walk($arr['igive'], function($v, $k) use (&$arr, $user_id){ ($arr['igive'][$k]['user_id'] == $user_id) ? ($arr['igive'][$k]['who_use'] = 1) : ''; }); print_r($arr);
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.30, 7.4.0 - 7.4.23, 8.0.0 - 8.0.11, 8.1rc1 - rc2
Array ( [igive] => Array ( [0] => Array ( [name] => Alex [shop_name] => Shop1 [rights] => admin [who_use] => 1 [user_id] => 765754346 ) [1] => Array ( [name] => Dmitry [shop_name] => Shop2 [rights] => manager [who_use] => [user_id] => 123456789 ) ) [giventome] => Array ( ) )

preferences:
67.3 ms | 461 KiB | 5 Q