Jump to content

adding rows and colums to a two dimentional array


stijn0713

Recommended Posts

So then...explain better.  There are dozens of ways to add things to an array.  The three most common:

 

$arr[] = $something;

array_push($arr, $something);

array_unshift($arr, $something);

 

If those don't fit your requirements, refine the requirements.

Link to comment
Share on other sites

Ok. This is my two dimentional array:

 

Array ( [0] => Array ( [0] => 21 [1] => 24 [2] => 18 [3] => 1 [4] => 0 [5] => 0 [6] => 0 ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 0 [4] => 1 [5] => 0 [6] => 0 ) [2] => Array ( [0] => 24 [1] => 29 [2] => 32 [3] => 0 [4] => 0 [5] => 1 [6] => 0 ) [3] => Array ( [0] => -1 [1] => -1 [2] => 2 [3] => 0 [4] => 0 [5] => 0 [6] => 1 ) )

 

which corresponds to this matrix:

 

21 24 18 1 0 0 0

01 02 03 0 1 0 0

24 29 32 0 0 1 0

-1 -1  02 0 0 0 1

 

Which is indexed as:

 

00 01 02 03 04 05 06

10 11 ....

20 21 ...

 

etc.

 

Now i need to add this array (x1 => 7500, x2 => 8200, x3 => 10500, t1 => 0, t2 =>0, t3 => 0, t4 => 0) so that my matrix will be:

 

7500 8200 10500 0 0 0 0

x1 x2 x3 t1 t2 t3 t4

21 24 18 1 0 0 0

1 2 3 0 1 0 0

24 29 32 0 0 1 0

-1 -1 2 0 0 0 1

 

So in fact i need to add the values or the keys of an array into a row of a two dimentional array...

 

Hope it clears things out

Link to comment
Share on other sites

Foremost, Arrays do not have rows and columns.  They have keys and values.

 

Array ( 
    [0] => Array ( 
        [0] => 21   [1] => 24 [2] => 18  3] => 1  [4] => 0 5] => 0 [6] => 0 
    ) 
    [1] => Array ( 
        [0] => 1 [1] => 2 [2] => 3[3] => 0 [4] => 1[5] => 0  [6] => 0 
    ) 
    [2] => Array ( 
        [0] => 24  [1] => 29 [2] => 32  [3] => 0  [4] => 0 [5] => 1 [6] => 0
    ) 
    [3] => Array ( 
        [0] => -1 [1] => -1 [2] => 2 [3] => 0 [4] => 0 [5] => 0 [6] => 1 
    )
)

Now i need to add this array (x1 => 7500, x2 => 8200, x3 => 10500, t1 => 0, t2 =>0, t3 => 0, t4 => 0) so that my matrix will be:

 

7500  8200  10500  0  0  0  0

x1  x2  x3  t1  t2  t3  t4

 

Are the x#'s supposed to be keys or values?  You show them both ways. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.