First of all I don't understand what this code is doing. I will put part of the var dump below. What I expected it to do was have 10 ids generated.
Instead it has about 10 arrays of ids.
Second, what I want to do is turn the ids into a list. Say I only had 10 $ids.
From reading the manual on the list() function I would do something like this in order
to index the ids and create a mapped list.
$i=0;
list($list($ids) = $ids
$i++;
thanks,
function foo($j) {
$ids = array();
while (count($ids) < $j) {
$i=0;
$id = gen_id(); // assume this function will return you an integer
if (!in_array($id, $ids)) {
$ids[] = $id;
var_dump($ids);
}
}
}
function gen_id(){
$c=rand (0, getrandmax());
echo $c;
return $c;
}
foo(10);
results:
836025423array(1) { [0]=> int(836025423) } 1057001051array(2) { [0]=> int(836025423) [1]=> int(1057001051) } 1853518720array(3) { [0]=> int(836025423) [1]=> int(1057001051) [2]=> int(1853518720) } 1895027043array(4) { [0]=> int(836025423) [1]=> int(1057001051) [2]=> int(1853518720) [3]=> int(1895027043) } 36424840array(5) { [0]=> int(836025423) [1]=> int(1057001051) [2]=> int(1853518720) [3]=> int(1895027043) [4]=> int(36424840) } 31443683array(6) { [0]=> int(836025423) [1]=> int(1057001051) [2]=> int(1853518720) [3]=> int(1895027043) [4]=> int(36424840) [5]=> int(31443683) } 1383785487array(7) { [0]=> int(836025423) [1]=> int(1057001051) [2]=> int(1853518720) [3]=> int(1895027043) [4]=> int(36424840) [5]=> int(31443683) [6]=> int(1383785487) } 547249641array(8) { [0]=> int(836025423) [1]=> int(1057001051) [2]=> int(1853518720) [3]=> int(1895027043) [4]=> int(36424840) [5]=> int(31443683) [6]=> int(1383785487) [7]=> int(547249641) } 2142797075array(9) { [0]=> int(836025423) [1]=> int(1057001051) [2]=> int(1853518720) [3]=> int(1895027043) [4]=> int(36424840) [5]=> int(31443683) [6]=> int(1383785487) [7]=> int(547249641) [8]=> int(2142797075) } 374229833array(10) { [0]=> int(836025423) [1]=> int(1057001051) [2]=> int(1853518720) [3]=> int(1895027043) [4]=> int(36424840) [5]=> int(31443683) [6]=> int(1383785487) [7]=> int(547249641) [8]=> int(2142797075) [9]=> int(374229833) }