$data=array(0,1,2,3,4,5,6,7,8,9);
for($i=0;$i<6;$i++){
$tmp[] = array_land($data);
}
foreach($tmp as$item){
echo$item."\n";
}
I'd like to randomly display the number of 6 of them and display which number and how many duplicates, but how can I do it?
php
You can count distributions using the array_count_values
function that comes standard with PHP.
/*Original data array*/
$data=range(0,9);
/* Array containing data taken from $data at random */
$items=[];
/* Get 6 at random*/
for($i=0;$i<6;$i++){
$items[] = array_land($data);
}
/* Take Statistics*/
$stat=array_count_values($items);
/* Output */
echo "items:";
foreach($items as$item){
echo$item, "";
}
echo "\n";
echo "statistics:\n";
foreach($stat as$item=>$count){
echo "", $item, ":", $count, "times\n";
}
-- This answer is based on comment from metropolisIt's written.
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
582 PHP ssh2_scp_send fails to send files as intended
917 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.