Daily Archives Monday, March 2007

PHP: XOR swap

The XOR swap lets you swap the value of integer variables without using a temporary variable, it's also slightly faster.
PLAIN TEXT
PHP:

$x ^= $y;

$y ^= $x;

$x ^= $y;

I can't actually think of a good reason Why you'd want to use this in PHP since memory isn't normally a big issue, however it might be good [...]

JS: Unobtrusive Select All Checkboxes

I wrote last week about how I’m trying to improve my JavaScript skills. As a small exercise I have written this function for unobtrusively selecting/deselecting checkboxes in a form.
PLAIN TEXT
JAVASCRIPT:

function selectAll(box)

{

// get the elements name

var id = box.id;

var name = /^([a-z]+)(_select_all)$/i.exec(id);

 

name = name[1];

 

re = new RegExp('^'+name+'_[0-9]+$');

 

// get the elements stauts

var state = box.checked;

 

// get the [...]