note 60281 added to function.array-rand

From: Date: Mon, 02 Jan 2006 00:18:16 +0000
Subject: note 60281 added to function.array-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-101092@lists.php.net to get a copy of this message
This is something I have been playing with for quite awhile. I'm very new to php, but i finally got it to work. it's a function that will take and array[$arrquo] and find a particular keyword[$find] in the different elements of the array then take those elements that posess that keyword and display them at random <?php function popbyword($arrquo,$find) { $newarr = array(''); foreach($arrquo as $line) { if( strstr( $line, $find ) ) { array_push($newarr, $line); } } srand((double)microtime()*1000000); $rquote = array_rand($newarr); echo $newarr[$rquote]; } popbyword($images, 'Albert'); ?> In my case I had this huge array of quotes with 90 some elements. I was able to find certain keywords in those elements then ONLY display the elements that had those keywords. NEAT! Maybe only because I'm new. ---- Manual Page -- http://www.php.net/manual/en/function.array-rand.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60281 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60281&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60281&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60281&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60281&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60281&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60281&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60281&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60281&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101092) next »