PHP 4.0 Bug #5889: pack() does not take arrays
| From: | tomwk at audiogalaxy dot com | Date: | Tue, 01 Aug 2000 07:51:18 +0000 |
| Subject: | PHP 4.0 Bug #5889: pack() does not take arrays | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-27198@lists.php.net to get a copy of this message | ||
From: tomwk@audiogalaxy.com
Operating system: Redhat Linux
PHP version: 4.0.1pl2
PHP Bug Type: Feature/Change Request
Bug description: pack() does not take arrays
I have an application that writes data across our network
to another program. Most of the data consists of integer arrays. I'm currently doing this in
a very simple manner,
using something like this:
for( $i = 0; $i < $numInts; $i++ ) {
fwrite( $fd, pack( "N", $ints[ $i ] ) );
}
However, this results in a very large number of calls to
fwrite, which is bad for performance. I made the routine
about 3 times faster by doing something like this:
fwrite( $fd, pack( "N10"
$ints[ $i + 0 ],
$ints[ $i + 1 ],
$ints[ $i + 2 ], ///.. and so on,
However, it would be really great if pack could take an array as one of it's arguments. I
believe this is the way
Perl behaves, but when I try:
$data = array( 10, 123 );
$buf = pack( "N*", $data );
$valArray = unpack( "N*", $buf );
while( list( $key, $val ) = each( $valArray ) ) {
echo "$key -> $val\n";
}
the only output I get is:
1 -> 1