"Pjotr Wedersteers" wrote:
I have source information in a file, and (part of) this information
comes as
coordinates.
A coordinate consists of a letter followed by a number, ranging
from a1 to
i9
I’d like to count the number of occurrences of each coordinate,
and put them
in a matrix.
The matrix should look like this (metasyntax):
matrix = array [’a’..’i’][1..9]
Later on in the script I’d like to be able to refer to a cell in
the matrix
by using the same letter/number combo.
I know I can define an array using strings as keys, but how can I
define
a..i as keys without the need to specify them all individually?
TIA
Pjotr
Hope this helps.
Read the coordinates from the file. I assume after you read then, they
are going to be in an array called $coor, where $coord would have
values like ’a1’ , ’b5’, etc.
Then do this:
foreach ($coord as $line) {
$alpha = preg_replace("/\d/", ’’, $line); //leaves only the
alpha part
$num = preg_replace("/\D/", ’’, $line); //leaves the numeric
part only
$newcoord[$alpha][$num] += 1; //increment count
}
You now have the counts for each coordinate combination.
--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL:
http://www.dbForumz.com/PHP-Array-in...ict131894.html
Visit Topic URL to contact author (reg. req'd). Report abuse:
http://www.dbForumz.com/eform.php?p=440194