[thelist] PHP: Inserting data from one column of data to the first index in a multideminsional array

Carl J Meyer cjmeyer at npcc.net
Wed Mar 12 14:40:02 CST 2003


On Wed, 2003-03-12 at 12:12, **1st Vamp** wrote:
> Example:
> $array[0] = 'tick';
> $array[1] = 'tock';
> $array[0][0] = 'foo';
> $array[1][0] = 'bar';

This array is not possible in PHP.  If $array[0][0] has a value, then
$array[0] must be an array, not a string (such as 'tick').

If you're treating a multidimensional array as a table, and your "table"
looks like this:
        col0  |   col1
row0 | 'tick' |  'foo'
row1 | 'tock' |  'bar'

Then your PHP array could look like
$array[0][0] = 'tick';
$array[0][1] = 'tock';
$array[1][0] = 'foo';
$array[1][1] = 'bar';

And if you want to set the values in the first column equal to the
values in the Nth column of such a table:

$array[0] = $array[N];

HTH,
Carl



More information about the thelist mailing list