Re: Array Push question

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

 



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



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
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