2016-07-01 33 views
0

我有這樣的多維數組:多維序列化陣列 - 提取數據 - 計數所提取的數據和排序AZ

Array ( 
[0] => a:7:{s:21:"mage_form_post_status";s:5:"draft";s:19:"mage_form_post_type";s:4:"post";s:25:"mage_form_post_permission";s:6:"public";s:21:"mage_form_post_author";s:1:"1";s:23:"mage_form_post_redirect";s:1:"0";s:19:"mage_form_post_edit";b:0;} 
[1] => a:4:{s:14:"mage_your_name";s:14:"George Jackson";s:15:"mage_your_email";s:24:"[email protected]";s:13:"mage_who_name";s:8:"Gym Goer";s:10:"mage_video";s:0:"";} 
[2] => a:7:{s:21:"mage_form_post_status";s:5:"draft";s:19:"mage_form_post_type";s:3:"gym";s:25:"mage_form_post_permission";s:6:"public";s:21:"mage_form_post_author";s:1:"1";s:23:"mage_form_post_redirect";s:2:"88";s:19:"mage_form_post_edit";b:0;} 
[3] => a:2:{s:15:"mage_tags_input";s:0:"";s:14:"mage_your_name";s:5:"Denis";} 
[4] => a:1:{s:14:"mage_your_name";s:5:"Denis";} 
[5] => a:2:{s:13:"mage_gym_name";s:12:"Fanna - test";s:14:"mage_your_name";s:4:"John";} 
[7] => a:2:{s:13:"mage_gym_name";s:11:"Boss - test";s:14:"mage_your_name";s:4:"Rudy";} 
[8] => a:6:{s:21:"mage_form_post_status";s:5:"draft";s:19:"mage_form_post_type";s:4:"post";s:25:"mage_form_post_permission";s:11:"contributor";s:21:"mage_form_post_author";i:0;s:20:"mage_form_post_email";s:0:"";s:23:"mage_form_post_redirect";i:0;} 
[9] => a:2:{s:13:"mage_gym_name";s:11:"Batt - test";s:14:"mage_your_name";s:3:"Ann";} 
[10] => a:2:{s:13:"mage_gym_name";s:11:"Boss - test";s:14:"mage_your_name";s:6:"Freddy";} 
) 

我想顯示導致這樣在AZ順序:

巴特 - 試驗(1 )

老闆 - 試驗(2)

凡娜 - 試驗(1)

你能幫我嗎?

+0

那麼你有什麼試圖去做。所以**不是免費的編碼服務** – RiggsFolly

+0

'array_map('unserialize',$ arr)'並照常工作 – splash58

回答

0

(自PHP 5.5可用),array_count_valuesksort功能使用array_mapunserializearray_column解決辦法:

// $serialized_data is your initial array 

$unserialized = array_map('unserialize', $serialized_data); 
$gym_names = array_column($unserialized, 'mage_gym_name'); // getting all 'mage_gym_name' entries 
$counts = array_count_values($gym_names); 
ksort($counts); // sorting by keys 

print_r($counts); 

輸出將相似於以下內容:

Array 
(
    [Batt - test] => 1 
    [Boss - test] => 2 
    .... 
) 
+0

我是triyng來實現你的代碼,這部分代碼打破了其餘的代碼:array_column($反序列化,'mage_gym_name'); –

+0

我寫過*自PHP 5.5起可用* - 檢查您的PHP版本 – RomanPerekhrest

+0

您是絕對正確的,我的託管使用PHP 5.4.45版本 –