Re: Array Push question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As you guys can probably guess from the question I'm still getting to grips with some parts of php.

I had stripped down the code for my original post, maybe this will clear things up a bit:

$Rows[] = array();
$currentRow = count($Rows) - 1;
$Rows[$currentRow]['test'] = "this is a test";
$Rows[$currentRow]['Data'] = array();
$Rows[$currentRow]['Config'] = "This is the row config";

So from what you guys have said I have changed it to be the following:

$Rows[] = array('test' => 'this is a test', 'Data' => array(), 'Config' => 'This is the row config');

Which seems to be doing what I want.

Thanks for the replies,
 JC


Jim Lucas wrote:
John Comerford wrote:
Hi Folks,

Is there a better way of doing the following:

$Rows[] = array();
$currentRow = count($Rows) - 1;
$Rows[$currentRow]['test'] = "this is a test";

I imagine that you are doing other actions between the above three lines? Correct?

Really, the simplest way of doing this is to call this over and over again.

$Rows[]['test'] = "this is a test";

it will give you the same results as array_push, but without a function call

$Rows[]['test'] = "this is a test";
$Rows[]['test'] = "this is another test";
$Rows[]['test'] = "this is even another test";

print_r($Rows);

this will show you that it does what you are doing in the above code, but again, the question. What are you doing between all the lines of code that made you think that you had to do it your example way? Are you using count() and doing math with it? or something else?


Specifically I am wonder if I can avoid having to use 'count'.

TIA,
 JC


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux