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 to get a value of 'shop_nam'e where 'user_id' = 123456789;*/ $user_id = '765754346'; $shop_name = ''; array_walk($arr['igive'], function($v, $k) use (&$shop_name, $user_id){ ($v['user_id'] == $user_id) ? ($shop_name = $v['shop_name']) : ''; }); echo $shop_name;
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
Shop1

preferences:
79.42 ms | 459 KiB | 5 Q