How to convert the value of an array into a new array by name

Source: Internet
Author: User
How to convert the value of the array into the health name to form a new array. This post was last edited by xuexi123abc163 from 2014-11-2411: 40: 57 (& nbsp; [0] & nbsp; & gt; & nbsp; Array & nbsp; & How does nb convert the value of an Array into a new Array by name.

This post was last edited by xuexi123abc163 at 11:40:57


(
[0] => Array
(
[Ak] => 1
[Fs] => 12
[Tss] => sd third-party f
)

[1] => Array
(
[Ak] => 2
[Fs] => 12
[Tss] => Yes
)

[2] => Array
(
[Ak] => 3
[Fs] => 22
[Tss] => Good News
)

[3] => Array
(
[Ak] => 4
[Fs] => 22
[Tss] => octal score
)
[4] => Array
(
[Ak] => 6
[Fs] => 22
[Tss] => octal score
)
)

The above array is $ abc
I want to form a new array, take the fs value as the key name, and then use the same fs value to form a new array ,..

The array is as follows:

(
[12] => Array
(
[0] => Array
(
[Ak] => 2
[Tss] => Yes
)
[1] => Array
(
[Ak] => 2
[Tss] => Yes
)
)

[22] => Array
(
...............
)
)





------ Solution ----------------------
$ Ar = array (
Array (
'AK' => '1 ',
'Fs' => '12 ',
'Oss '=> 'SD third-party f ',
),
Array (
'AK' => '2 ',
'Fs' => '12 ',
'Tss' => 'Yes ',
),
Array (
'AK' => '3 ',
'Fs' => '22 ',
'Oss '=> 'New play ',
),
Array (
'AK' => '4 ',
'Fs' => '22 ',
'Tss' => 'eight real rating ',
),
Array (
'AK' => '6 ',
'Fs' => '22 ',
'Tss' => 'eight real rating ',
),
);
$ Res = array ();
Foreach ($ ar as $ r ){
$ T = $ r ['Fs'];
Unset ($ r ['Fs']);
$ Res [$ t] [] = $ r;
}
Print_r ($ res );
Array
(
[12] => Array
(
[0] => Array
(
[Ak] => 1
[Tss] => sd third-party f
)

[1] => Array
(
[Ak] => 2
[Tss] => Yes
)

)

[22] => Array
(
[0] => Array
(
[Ak] => 3
[Tss] => Good News
)

[1] => Array
(
[Ak] => 4
[Tss] => octal score
)

[2] => Array
(
[Ak] => 6
[Tss] => octal score
)

)

)

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.