Tag Archives: multi-dimensional

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 »

Two-Dimensional Array Searching in PHP

Tested with PHP 5.3.1

PHP’s array_search function is great! No longer must we single-step through every element of an array to find what we’re looking for. Too bad it only works on single-dimension arrays.

Read more »