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

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

1) The code above will produce a $currentRow of -1 which is probably not what you want.

2) If you actually mean that you have an array that contains items and you want the last one, used end (http://php.net/end).

3) I'm not really sure what the context is, but this is a very odd way of working with arrays. Either you already know the key or you don't. If you're just trying to append to the array you can do that with the following syntax... $Rows[] = array('test' => 'this is a test');

-Stut

--
http://stut.net/

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