php - Multi-dimensional array - uasort has no effect, usort removes keys -


Like a complex sorting requirement, the data looks like this:

  array (size = 238) ) 527 = & gt; Array (size = 2) 0 = & gt; Array (size = 5) 'person_name' = & gt; String 'Ms. Sandra Stokes I '(Length = 19)' archive_id '= & gt; Int 1 'archive_item_id' = & gt; Int 1 'meta_data_id' = & gt; Int 28151 'person_id' = & gt; Int 527 1 = & gt; Array (size = 5) 'person_name' = & gt; String 'Ms. Sandra Stokes I '(Length = 19)' archive_id '= & gt; Int 1 'archive_item_id' = & gt; Int 22 'Meta_Data_ID' = & gt; Int 28418 'person_id' = & gt; Int 527 766 = & gt; Array (size = 6) 0 = & gt; Array (size = 5) 'person_name' = & gt; String 'Riket Ichmann' (length = 14) 'archive_id' = & gt; Int 1 'archive_item_id' = & gt; Int 1 'meta_data_id' = & gt; Int 28251 'person_id' = & gt; Int 766 1 = & gt; Array (size = 5) 'person_name' = & gt; String 'Riket Ichmann' (length = 14) 'archive_id' = & gt; Int 1 'archive_item_id' = & gt; Int 10 'meta_data_id' = & gt; Int 28272 'person_id' = & gt; Int 766 2 = & gt; Array (size = 5) 'person_name' = & gt; String 'Riket Ichmann' (length = 14) 'archive_id' = & gt; Int 1 'archive_item_id' = & gt; Int 19 'meta_data_id' = & gt; Int 28378 'person_id' = & gt; Int 7663 = & gt; Array (size = 5) 'person_name' = & gt; String 'Riket Ichmann' (length = 14) 'archive_id' = & gt; Int 1 'archive_item_id' = & gt; Int 20 'Meta_Data_ID' = & gt; Int 28213 'person_id' = & gt; Int 766 4 = & gt; Array (size = 5) 'person_name' = & gt; String 'Riket Ichmann' (length = 14) 'archive_id' = & gt; Int 1 'archive_item_id' = & gt; Int 22 'Meta_Data_ID' = & gt; Int 2886 9 'person_id' = & gt; Int 766 5 = & gt; Array (size = 5) 'person_name' = & gt; String 'Riket Ichmann' (length = 14) 'archive_id' = & gt; Int 1 'archive_item_id' = & gt; Int 28 'meta_data_id' = & gt; Int 28135 'person_id' = & gt; Int 766  

Comparison function is used:

  function CMP ($ one, $ b) {if ($ one [0] ['PERSON_NAME' ] = = $ B [0] ['person_name']) {return 0; } Return ($ a [0] ['person_name']  $ b [0] ['person_name'])? -1 1; } Usort ($ data, "CMP");  

With usort, the return person is arranged in the order of the first name of the alphabet, so it is like, but detaching the id index closed:

  "Person_ids" [[ "Wykti_nam": "Abner Baker", "Arkaiv_aidi": 1, "Arkaiv_aitm_aidi": 2, "Meta_deta_aidi": 28376, "Wykti_aidi": 538}] [{ "Wykti_nam": "Eddie Ligros "," "Archive_id": 1, "Archive_item_id" 8, "Meta_data_id": 28365, "Person_id": 606}, { "Person_name": "Eddie Ligros", "Arkev_aidi": 1, "Sngrh_aitm_aidi": 20 , "Meta_Data_ID": 28,594, "per son_id ": 606}, {" PERSON_NAME ":" Eddie LeGros "," archive_id ": 1," archive_item_id ": 21," meta_data_id ": 28405," person_id ": 606}],  

With the Usure, the keys are protected but the function is not being applied.

  {"person_ids": {"502": [{"person_name": "Mr. Tara Bartoleti "," Arkaiv_aidi ": 1," Arkaiv_tam_aidi ": 15," Meta_deta_aidi ": 28247," Wykti_aidi ": 502}]," 503 ": [{" Wykti_nam ":" Stacey Adams "," Arkev_aidi ": 1 "Sngrh_tam_aidi" 8, "Meta_deta_aidi": 28 9 18, "Wykti_aidi": 503}, { "Wykti_nam": "Stacey Adams", "Arkev_aidi": 1, "Arkaiv_aitm_aidi": 22, "Meta_deta_aidi": 28682, "Wykti_aidi": 503}, { "PERSON_NAME": "Stacey Adams", "archive_id": 1, "archive_item_id": 26, "meta_data_id": 28,148, "person_id": 503}], "504": [ 

How to PERSON_NAME key gate Any advice on sorting up the ID key while completing the maintenance?

just below the sub array Should be sorted by:

  foreach ($ id = id => & amp; $ am_p; $ sub_array) {usort ($ sub_array, function ($ one, $ b) {return strcmp ($ One ['PERSON_NAME'], $ b ['PERSON_NAME']);})}} Var_dump ($ array);  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -