note 111165 added to function.rand

From: Date: Mon, 21 Jan 2013 19:37:45 +0000
Subject: note 111165 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-193303@lists.php.net to get a copy of this message
I wrote this script to clear some aspects about array_rand, array_filter and callback function array_filter's... It´s very simple, but maybe helps someone. <?php //Array 60 positions $numbers = range(1, 60); //Shuffle 60numbers shuffle($numbers); //Callback Function GET OUT zero with array_filter function retiraZero($item) {Return ($item != 0);} // More once time take rand numbers and Call retiraZero function $orte = array_filter(array_rand($numbers, 6), "retiraZero"); // Glue Up array $orte $numbersFinal = implode("-", $orte); // ShowUp result echo $numerosFinal; ?> Output likes: "num1 - num2 - num3 - num4 - num5 - num6" ps.: array_filter has a follow syntax : array_filter ( array $input [, callable $callback = "" ] )... But this can bring a parser ERROR likes : syntax error, unexpected T_FUNCTION in... because of this: i put Out callback function and calls it into this $orte = array_filter(array_rand($numbers, 6), "retiraZero"); ---- Server IP: 69.147.83.199 Probable Submitter: 177.205.162.18 ---- Manual Page -- http://php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/111165 Del: integrated -- https://master.php.net/note/delete/111165/integrated Del: useless -- https://master.php.net/note/delete/111165/useless Del: bad code -- https://master.php.net/note/delete/111165/bad+code Del: spam -- https://master.php.net/note/delete/111165/spam Del: non-english -- https://master.php.net/note/delete/111165/non-english Del: in docs -- https://master.php.net/note/delete/111165/in+docs Del: other reasons-- https://master.php.net/note/delete/111165 Reject -- https://master.php.net/note/reject/111165 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193303) next »