简体   繁体   中英

How to add an element to array?

How to add element to exist array? I have array:

Array ( [0] => Array ( [user_id] => 1 [user_login] => Saibamen [user_password] => 4028a0e356acc947fcd2bfshfh3w26gdshhbf00cef11e128d484a [user_email] => teeeest@test.pl [user_active] => 1 [user_last_login_ip] => 127.0.0.1 [user_perms] => ) )

I want add 'avatar' parametr to this array:

$avatar = md5($array_in_this_question[0]['user_email'])

您可以通过与读取值相同的方式添加值:通过使用其键

$array_in_this_question[0]['avatar'] = md5($array_in_this_question[0]['user_email']);

简单地使

$array[0]['avatar'] = $avatar

Well you'd need to assign the array to a variable for a start, so:

$theArray = Array ( [0] => Array ( [user_id] => 1 [user_login] => Saibamen [user_password] => 4028a0e356acc947fcd2bfshfh3w26gdshhbf00cef11e128d484a [user_email] => teeeest@test.pl [user_active] => 1 [user_last_login_ip] => 127.0.0.1 [user_perms] => ) );
$theArray[0]['avatar'] = md5($array_in_this_question[0]['user_email']);

is what you want I guess

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM