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

后端 未结 23 2757
逝去的感伤
逝去的感伤 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:33

    this code will help to change the oldkey to new one

    $i = 0;
    $keys_array=array("0"=>"one","1"=>"two");
    
    $keys = array_keys($keys_array);
    
    for($i=0;$i

    display like

    $keys_array=array("one"=>"one","two"=>"two");
    

提交回复
热议问题