PHP one-dimensional array reordering

Source: Internet
Author: User
Array (' id ' = 3, ' username ' = ' Alex ', ' parentname ' = ' John '
, ' proname ' = ' tttt ' num ' = 1, ' userid ' =>6, ' ParentID ' =>8,
' Cpid ' = 0, ' mobile ' = 15533336666, ' parentmobile ' and ' + 156477765465 ';
Put the last two in the 2nd and 4th positions, how do I reorder each other?
Array (' id ' = 3, ' username ' = ' Alex ', ' mobile ' and ' = 15533336666
, ' parentname ' = ' john ', ' Parentmobile ' and ' 156477765465 ', ' proname ' = ' tttt ' num ' = 1,
' UserID ' =>6, ' parentid ' =>8, ' cpid ' + 0);


Reply to discussion (solution)

$a = Array (  ' id ' = 3,  ' username ' = ' Alex ',  ' parentname ' = ' john ',  ' proname ' = ' tttt ', 
   ' num ' = 1,  ' userid ' =>6,  ' ParentID ' =>8,  ' cpid ' = +  0,  ' mobile ' and 15533336666, ' c10/> ' parentmobile ' = 156477765465); $k = Array (  ' id ',  ' username ',  ' mobile ',  ' ParentName ',  ' Parentmobile ',  ' proname ',  ' num ',  ' userid ',  ' parentid ',  ' cpid ',  ' mobile ', ; extract ($a); $b = Compact ($k); Var_export ($b);
Array (  ' id ' = + 3,  ' username ' = ' Alex ',  ' mobile ' = 15533336666,  ' parentname ' = ' John ',  ' parentmobile ' = ' 156477765465,  ' proname ' = ' tttt ',  ' num ' = 1,  ' userid ' and ' 6,  ' parentid ' = 8,  ' cpid ' and ' 0, '

Thank you, can you use only foreach to achieve it without extract and compact? Thank you.

If there is no sample, it is impossible to complete
What's the point of having a sample and sticking to the form?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.