Stut wrote:
Zoltán Németh wrote:
2007. 07. 12, csütörtök keltezéssel 10.28-kor Stut ezt írta:
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.

Maybe you didn't notice the [] in the first line of the OP's code?
I think this code should produce 0 for $currentRow, not -1.

Indeed, my bad. In that case the OP is better off creating the item in a temporary variable and then adding it to the array.

$row = array();
$row['test'] = 'this is a test';
$Rows[] = $row;

-Stut

what's wrong with skipping the temporary variable and just doing
$Rows[] = array('test'=>'this is a test');
?

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

Reply via email to