Posted By

jodm on 09/04/09


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


PHP File to byteArray

 / Published in: PHP

  1. <?
  2. $file = file_get_contents($_FILES['userfile']['tmp_name']);
  3. $byteArr = str_split($file);
  4. foreach ($byteArr as $key=>$val) { $byteArr[$key] = ord($val); }
  5. ?>

Report this snippet  


RSS Icon Subscribe to comments
Posted By: kirik on September 13, 2009

Why just not to use native php functions to apply function for each element of array? It will be way faster (and takes less memory) than foreach. $file = file_get_contents($_FILES['userfile']['tmp_name']); $byteArr = str_split($file); $byteArr = array_map('ord', $byteArr);

Posted By: ceolceol on January 23, 2011

@kirik I know this was a while ago, but there isn't any speed difference between foreach and array_map.

You need to login to post a comment.