In PHP, how do you change the key of an array element?

后端 未结 23 2706
逝去的感伤
逝去的感伤 2020-11-22 03:45

I have an associative array in the form key => value where key is a numerical value, however it is not a sequential numerical value. The key is actually an I

23条回答
  •  爱一瞬间的悲伤
    2020-11-22 04:43

    if your array is built from a database query, you can change the key directly from the mysql statement:

    instead of

    "select ´id´ from ´tablename´..."
    

    use something like:

    "select ´id´ **as NEWNAME** from ´tablename´..."
    

提交回复
热议问题