Array push with associate array

后端 未结 4 586
慢半拍i
慢半拍i 2020-12-10 11:30

If I am working with an associate array like such:

Array ( [Username] => user 
        [Email] => email 
      )

and I want to add an

4条回答
  •  不思量自难忘°
    2020-12-10 11:51

    You are using an associative array so you just set the key/value pair like this.

    $array["Password"] = pass;
    

    I think you may need to review the difference between an array and an associative array. For example if I ran the same command again with a different value it would overwrite the old one:

    $array["Password"] = "overwritten";
    

    Giving you this

    Array ( [Username] => user 
            [Email] => email
            [Password] => "overwritten"
          )
    

    Which judging by your question is not what your expecting

提交回复
热议问题