Associative arrays in C

Glib’s hash table. implements a map interface or (associative array). And it’s most likely the most used hash table implementation for C. GHashTable *table=g_hash_table_new(g_str_hash, g_str_equal); /* put */ g_hash_table_insert(table,”SOME_KEY”,”SOME_VALUE”); /* get */ gchar *value = (gchar *) g_hash_table_lookup(table,”SOME_KEY”);

Can PHP’s list() work with associative arrays?

With/from PHP 7.1: For keyed arrays; $array = [‘fruit1’ => ‘apple’, ‘fruit2’ => ‘orange’]; // [] style [‘fruit1’ => $fruit1, ‘fruit2’ => $fruit2] = $array; // list() style list(‘fruit1’ => $fruit1, ‘fruit2’ => $fruit2) = $array; echo $fruit1; // apple For unkeyed arrays; $array = [‘apple’, ‘orange’]; // [] style [$fruit1, $fruit2] = $array; // … Read more

Is there a way to find out how “deep” a PHP array is?

Here’s another alternative that avoids the problem Kent Fredric pointed out. It gives print_r() the task of checking for infinite recursion (which it does well) and uses the indentation in the output to find the depth of the array. function array_depth($array) { $max_indentation = 1; $array_str = print_r($array, true); $lines = explode(“\n”, $array_str); foreach ($lines … Read more

How to create an associative array in JavaScript literal notation

JavaScript has no associative arrays, just objects. Even JavaScript arrays are basically just objects, just with the special thing that the property names are numbers (0,1,…). So look at your code first: var myArray = []; // Creating a new array object myArray[‘a’] = 200; // Setting the attribute a to 200 myArray[‘b’] = 300; … Read more