note 68694 added to function.array-product

From: Date: Mon, 07 Aug 2006 20:56:19 +0000
Subject: note 68694 added to function.array-product
Groups: php.notes 
Request: Send a blank email to php-notes+get-115615@lists.php.net to get a copy of this message
This function can be used to test if all values in an array of booleans are TRUE. Consider: <?php function outbool($test) { return (bool) $test; } $check[] = outbool(TRUE); $check[] = outbool(1); $check[] = outbool(FALSE); $check[] = outbool(0); $result = (bool) array_product($check); // $result is set to FALSE because only two of the four values evaluated to TRUE ?> The above is equivalent to: <?php $check1 = outbool(TRUE); $check2 = outbool(1); $check3 = outbool(FALSE); $check4 = outbool(0); $result = ($check1 && $check2 && $check3 && $check4); ?> This use of array_product is especially useful when testing an indefinite number of booleans and is easy to construct in a loop. ---- Server IP: 66.163.161.117 Probable Submitter: 207.88.114.211 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.array-product.php Edit -- https://master.php.net/note/edit/68694 Del: integrated -- https://master.php.net/note/delete/68694/integrated Del: useless -- https://master.php.net/note/delete/68694/useless Del: bad code -- https://master.php.net/note/delete/68694/bad+code Del: spam -- https://master.php.net/note/delete/68694/spam Del: non-english -- https://master.php.net/note/delete/68694/non-english Del: in docs -- https://master.php.net/note/delete/68694/in+docs Del: other reasons-- https://master.php.net/note/delete/68694 Reject -- https://master.php.net/note/reject/68694 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115615) next »