[ create a new paste ] login | about

Link: http://codepad.org/Js9E3U1w    [ raw code | output | fork ]

PHP, pasted on Sep 12:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

function array_percentage($array, $percentage) 
{
    shuffle($array);
    $count = count($array);
    $result = array_slice($array, 0, ceil($count*$percentage/100));
    return $result;
}


$names = "foo\nbar\nbaz\nbaq\nlaz\nlaz\nlaz";
$namesArray = explode("\n", $names);

print_r(array_percentage($namesArray, 5));


Output:
1
2
3
4
Array
(
    [0] => laz
)


Create a new paste based on this one


Comments: