Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Sunday, 3 February 2013

Passing a named associative array via URL

Problem:

How do I manually pass an associative array via URL?

Solution:

Let's say we have an associative array named 'arr_args' with the key-value pairs 'key1'=>'value1', 'key2'=>'value2', i.e. arr_args = [key1=>value1, key2=>value2]. Let's also assume we have a sample script called 'sample.php' that will be receiving this associative array.

One way that you can pass this into a URL as the following:

sample.php?arr_args[key1]=value1&arr_args[key2]=value2

Tuesday, 8 May 2012

Clearing an array in Javascript

There are a few ways to clear an array in Javascript. Two particularly useful ways are as follows:
  1. Assigning a new array:
    myArray = [];
  2. Refactoring the current array:
    myArray.length = 0;

The first method will assign a new array to the myArray variable. If there are any other pointers to the previous array, these will still point to the old array.

The second method changes the array itself. If there are any other pointers to the previous array, they will all be updated to the cleared array.