PHP - Move element in array to second position


I have simple array from Wordpressmanage_posts_columns filter, to change the columns in custom post type admin. The array looks like

$columns = array ('lastname' => 'Lastname', 'firstname' => 'Firstname', 'city' => 'City' );

and I'm adding ID column

$columns['id'] = 'ID';

I would need to move the id element to second position in the array. How can this be done?




Instead, you can usearray_unshift to prepend elements onto an array, orarray_push to add an element at the end of the array.

To reorder the associative array, you can usearray_splice. A good example is here:

People are also looking for solutions to the problem: php - A way to not show 2 of 3 parameters in a url using .htaccess


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.