array


  • (HTML) Form element arrays

    Sometimes you might want to group form elements in arrays. Here’s a way to do that: [html] <form> <input type="text" name="textboxes[]"> <input type="text" name="textboxes[]"> <input type="text" name="textboxes[]"> </form> [/html] The structure of the $_POST array will then be: [php] Array ( [textboxes] => Array ( [0] => value 1 [1] => value 2 [2] =>…

  • (PHP) sorting an array on a specific value

    Simple way to sort an array with usort on a specific value using a comparator. [php] usort($myArray, function ($a, $b) { return $a[‘foo’] > $b[‘foo’]; }); [/php]

  • (C#) Swap two items in a generic list

    Put this in a static class. This will apply to Lists of any type. [c language=”language="#”] public static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB) { if (indexB > -1 && indexB < list.Count) { T tmp = list[indexA]; list[indexA] = list[indexB]; list[indexB] = tmp; } return list; } [/c] Simply call it like…