如何为php变量分配数组值[关闭]

In the following code how to assign array values to a php variable.

while($objResult = mysql_fetch_array($objQuery))
{
$cutomername[] = $objResult["firstname"];
$mailid[] = $objResult["mailid"];
$address[] = $objResult["address"];
$phonenumber[] = $objResult["phonenumber"];
$items[] = $objResult["itemname"];
$quantity[] = $objResult["quantity"];
$total[] = $objResult["grandtotal"];

    $name = $cutomername[];
    $mail = $mailid[];
    $addr = $address[];
    $phnum = $phonenumber[];
    $itm = $items[];
    $qty = $quantity[];
    $tot = $total[];
}

You could assign your two variables at once using something like this:

while($objResult = mysql_fetch_array($objQuery))
{
  $name = $cutomername[] = $objResult["firstname"];
  $mail = $mailid[] = $objResult["mailid"];
  $addr = $address[] = $objResult["address"];
  $phnum = $phonenumber[] = $objResult["phonenumber"];
  $itm = $items[] = $objResult["itemname"];
  $qty = $quantity[] = $objResult["quantity"];
  $tot = $total[] = $objResult["grandtotal"];
}
$name = $customername[count($customername)-1];

And so forth for every variable.

Alternatively, you could store length before assigning $total like that

$len = count($customername)-1;

And then for every variable just write like that:

$name = $customername[$len];