php - Reorder array but don't change keys -


e.g .i have array:

$myarray = (    [0] => 'first',   [1] => 'second',   [2] => 'third',   [3] => 'fourth'  ); 

and need this:

$myarray = (    [0] => 'fourth',   [1] => 'third',   [2] => 'second',   [3] => 'first'  ); 

so, can stored in database in reverse order when compared original array.

i have tried krsort($myarray); result not want, because creates this:

$myarray = (    [3] => 'fourth',   [2] => 'third',   [1] => 'second',   [0] => 'first'  ); 

and want keys stay in original array.

and problem can not sort values e.g. letters using arsort() etc. because different (different strings, without meaning or order system).

any idea how that?

if want reverse array, use array_reverse.

$myarray = array_reverse($myarray); 

result:

array (     [0] => fourth     [1] => third     [2] => second     [3] => first ) 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -