RE: [PHP] How do I convert an array into a mask?

From: Date: Wed, 06 Nov 2002 14:06:40 +0000
Subject: RE: [PHP] How do I convert an array into a mask?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-123004@lists.php.net to get a copy of this message
At 13:43 06.11.2002, Daevid Vincent said: --------------------[snip]-------------------- >Ernest, close but you have it reversed for my needs (i.e. true binary >form). Notice that my LSB is to the left, not right. Ah, ic, you want a <<string>> like "00001100101" - that's easy :) Note that I do _not_ pass the array by reference here since I modify it (using asort). function make_a_special_bitlike_string($array) { $result = ''; sort($array, SORT_NUMERIC); $max = $array[count($array)-1]; for ($i = 1; $i <= $max; ++$i) { if (in_array($i, $array)) $result .= '1'; else $result .= '0'; } return $result; } if you need this as a number, simply return "(int)$result", but beware that this breaks if there are more than 32 digits (highest value > 32). -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#123004) next »