Tag Archives: array

Creating Objects in JavaScript

Oh, hello. It has been awhile, hasn’t it? Well, I’ve been bouncing around between projects–I tend to do that a lot–and have had long stretches of time where I don’t work on anything–I also do that a lot.

Most recently, my current project has required me to dive into JavaScript; a language I have largely avoided in all my years. But, once you get over the camel case, it’s not so bad. It’s even possible to create objects, in a roundabout, completely non-obvious way. Once I knew what to look for (composite data types), I realized the solution was out there a bit, but since I refer back to my own blog quite a bit when I forget something–and with so long between coding sessions, it’s no wonder–it’s probably a good idea to repeat it here.
Read more »

Counting Rows Returned by an SQLite3 Query in PHP

Tested with PHP 5.3.1

Strangely, when running queries against an SQLite3 database, there is no obvious way to know how many rows were returned by a specific query. After much hunting, I found a solution in the PHP manual, of all places.

Let’s say we have a table with 4 columns (id, seed, name, score), with 3 rows. The rest you need to know is in the code comments, really. Read more »

Scaling/Blowing Up a Two-Dimensional Array in PHP

Tested with PHP 5.3.1

In an upcoming post (Sightlines, or: Drawing Virtual Lines in a Two-Dimensional PHP Array Using Bresenham’s Line Algorithm), I’ll explain why I need to scale/blow up an array to 10x it’s size. Until then, this code snippet might not seem so useful. But, most everything I have written thus far has been leading up to the aforementioned post, and this is certainly a part of it. Read more »

Dynamically Creating Two-Dimensional Arrays in C++

C++ doesn’t take kindly to dynamic arrays. You can’t just plug a variable into some brackets and expect to make an array whatever size you want. There are technical reasons for this–compile time code v. run time code–but at the end of the day, it just isn’t happening.

However, it wouldn’t be a very useful language if there wasn’t some way to dynamically create arrays, so if you want to do it, you’re going to have to play with pointers. Doubly so (pun wholly and completely intended) for 2D arrays.

Read more »

Two-Dimensional Array Slicing in PHP

Tested with PHP 5.3.1

The array_slice function in PHP is a handy way to copy a chunk of information from one array to second array. This is useful to examine or modify some interesting set of data without mucking about with your original set, or cutting down on the size and overhead of operations, because you’re running them against a more compact array.

The function works on two-dimensional arrays, but in an unexpected way. Read more »