note 119488 added to function.array-product

From: Date: Mon, 20 Jun 2016 07:22:06 +0000
Subject: note 119488 added to function.array-product
Groups: php.notes 
Request: Send a blank email to php-notes+get-205757@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: 72.52.91.14 Probable Submitter: 122.165.131.253 ---- Manual Page -- http://php.net/manual/en/function.array-product.php Edit -- https://master.php.net/note/edit/119488 Del: integrated -- https://master.php.net/note/delete/119488/integrated Del: useless -- https://master.php.net/note/delete/119488/useless Del: bad code -- https://master.php.net/note/delete/119488/bad+code Del: spam -- https://master.php.net/note/delete/119488/spam Del: non-english -- https://master.php.net/note/delete/119488/non-english Del: in docs -- https://master.php.net/note/delete/119488/in+docs Del: other reasons-- https://master.php.net/note/delete/119488 Reject -- https://master.php.net/note/reject/119488 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205757) next »