使用PHP中的键将项添加到数组

How to add array items to an existing array with key => value ? actually i want to create an array of mysql rowset i.e.

$n =0;
while($row = mysql_fetch_array($rowset))
{
   $array[$n] = array('name' => $row['name'], 'city' = $row['city']);
   $n += 1;
}

Thanks.

Just try with:

$existingArray['newKey'] = 'new value';

Or use array_merge function:

$newArray = array_merge($existingArray, $additionalData);

http://php.net/manual/en/function.array-merge.php

That what you're looking for?

-edit-

Just to note, if conflicting results are found, the last most array entry will be used. If you array merge three arrays with id fields, only the final arrays id will be stored in the result.

You may want to look into this:

http://php.net/array_push

Should be simple enough.

For One:

$array['key'] = $value;

Merge:

$mergedArray = array_merge($array1, $array2);

(http://php.net/manual/en/function.array-merge.php)