Friday, 27 March 2015

PHP: What's different with SplFixedArray, and is it best to use?

SplFixedArray is as the name says a fixed size array: You specify the size in the constructor and can only change it later using ->setSize(). But it is not changed automatically. Also you can only use integers as indexes (=> no assoc arrays). So you can't always use an SplFixedArray when you're using a PHP array (and also shouldn't). But if you are having really large arrays that do not change, then using it can save you some memor...

PHP: array_merge_recursive() vs. array_replace_recursive()

If you’ve been coding in PHP for a while, you have probably used array_merge() at some point. It’s been around since PHP 4, and like most PHP functions, it does largely what you’d expect it to do. If you have arrays with numeric indices, it re-indexes and appends subsequent arrays to the first array argument. print_r(array_merge(     array('a', 'b'),     array('c', 'd') )); /* the above will output: Array (     [0] => a     [1] => b     [2]...

Thursday, 19 March 2015

Convert Numbers to Words with PHP

<?php function convert_number_to_words($number) {         $hyphen      = '-';     $conjunction = ' and ';     $separator   = ', ';     $negative    = 'negative ';     $decimal     = ' point ';     $dictionary  = array(         0                  ...