我遵循PHP代码:
$age = array_merge($age,array(get_user_meta($comment->user_id, 'wsl_user_age', true)));
这会产生:
Array
(
[0] => 26
[1] =>
[2] => 18
[3] => 28
[4] => 22
[5] => 21
[6] => 26
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
我想要的是26 18等作为键。并且重复它重复的次数,实质上是重复计数。
我试过了:
$age = array_merge($age,array(get_user_meta($comment->user_id, 'wsl_user_age', true)=> ""))
但这产生了绝对的废话。
我该怎么办?
答案 0 :(得分:0)
我认为您正在寻找array_count_values
$cnt_array = array_count_values($your_array);
echo "<pre>";
print_r($cnt_array);
参考:http://www.php.net/manual/en/function.array-count-values.php
答案 1 :(得分:0)
您可能正在寻找http://codepad.org/RDUhltQ7
看看
答案 2 :(得分:0)
$foo = Array
( 26,
18,
28,
22,
21,
26,
'',
''
);
$foo = array_filter($foo);
$foo = array_count_values($foo);
print_r($foo);
http://sandbox.onlinephpfunctions.com/code/a1875256f4680b06b9d909bdb3329cfcd64d44de