輸入N個(gè)數(shù)組,統(tǒng)計(jì)不同元素出現(xiàn)的次數(shù)
<?php
class
Statistics {
public
$meta
=
array
();
public
$result
;
private
$meger
=
array
();
function
__construct() {
$this
->meta[] = func_get_args();
}
public
function
show() {
foreach
(
$this
->meta[0]
as
$value
) {
foreach
(
$value
as
$subvalue
) {
if
(!in_array(
$subvalue
,
$this
->meger)) {
$this
->meger[] =
$subvalue
;
$this
->result[
"$subvalue"
] = 1;
}
elseif
(in_array(
$subvalue
,
$this
->meger)) {
$this
->result[
"$subvalue"
] ++;
}
}
}
print_r(
$this
->result);
}
}
$arr1
=
array
(
'a'
,
'b'
,
'd'
);
$arr2
=
array
(
'd'
,
'de'
,
'ef'
);
$arr3
=
array
(
'a'
,
'ef'
,
'r'
,
'q'
);
$arr4
=
array
(
'b'
,
'de'
,
'q'
,
'z'
);
$arr5
=
array
(
'1'
,
'de'
,
'q'
,
'3r'
);
$arr6
=
array
(1, 2,
'mn'
,
'0y'
);
$arr7
=
array
(1,
'v2d'
,
'mn'
,
'0y'
);
$s
=
new
Statistics(
$arr1
,
$arr2
,
$arr3
,
$arr4
,
$arr5
,
$arr6
,
$arr7
);
$s
->show();
?>
推薦文章
2024-11-28
2024-06-25
2024-01-04
2023-11-06
2023-10-30
2023-10-13
2023-10-10
穩(wěn)定
產(chǎn)品高可用性高并發(fā)貼心
項(xiàng)目群及時(shí)溝通專業(yè)
產(chǎn)品經(jīng)理1v1支持快速
MVP模式小步快跑承諾
我們選擇聲譽(yù)堅(jiān)持
10年專注高端品質(zhì)開(kāi)發(fā)聯(lián)系我們
友情鏈接: