0

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

Array ( [0] => Array ( [user_id] => 1 [user_login] => Saibamen [user_password] => 4028a0e356acc947fcd2bfshfh3w26gdshhbf00cef11e128d484a [user_email] => [email protected] [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'])

3 Answers 3

1

You add value the same way as when you read a value: By using its key(s)

$array_in_this_question[0]['avatar'] = md5($array_in_this_question[0]['user_email']);
Sign up to request clarification or add additional context in comments.

Comments

0

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] => [email protected] [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

Comments

0

Simply make

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

1 Comment

This would add the value to the outer hash, not the internal one (which he probably wants).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.