如何向数组添加元素?

时间:2011-08-23 20:24:25

标签: php arrays

如何将元素添加到存在的数组?我有阵列:

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] => ) )

我想在此数组中添加'avatar'参数:

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

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

简单地制作

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

答案 2 :(得分:0)

你需要将数组分配给一个变量作为开始,所以:

$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']);

是你想要的我猜

相关问题