我有一个多维数组:
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:"amy.thompson41@gmail.com";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";}
)我想按A顺序显示这样的结果:
Batt -测试(1)
Boss -测试(2)
Fanna测试(1)
你能帮帮我吗?
发布于 2016-07-01 10:56:26
该解决方案使用array_map、unserialize、array_column(可从PHP5.5中获得)、array_count_values和ksort函数:
// $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
....
)https://stackoverflow.com/questions/38143216
复制相似问题