Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Archive for May, 2012

PHP functions in JavaScript

Saturday, May 5th, 2012 by Servage
If you're very familiar with PHP and also use JavaScript, you might find it confusing, yet annoying that some great functions aren't available in both languages. phpjs.org is a project were you can find JavaScript functions that replicate PHP functions. This is really nice to add missing functionality to JavaScript, which you are used to under PHP. Example I've picked a random example, namely the array_pop function which is available in PHP and pops and element of the end of an array. This functionality isn't available in JavaScript, so it's great you can get it form phpjs: function array_pop (inputArr) { // Pops an element off the end ...

Merge arrays recursively without duplication in PHP

Wednesday, May 2nd, 2012 by Servage
The default array_merge_recursive function in PHP is great, but I find myself wanting something else much more often, which isn't possible in PHP by default, unfortunately. When using array_merge_recursive you merge two arrays, which may not be what you really want. Considder the example from the PHP manuel: $ar1 = array("color" => array("favorite" => "red"), 5); $ar2 = array(10, "color" => array("favorite" => "green", "blue")); $result = array_merge_recursive($ar1, $ar2); print_r($result); Output: Array ( [color] => Array ( [favorite] => Array ( ...