简体   繁体   中英

loop using while with a multidimensional array php

i'm trying to make a while in my multidimensional array like this:

$address = array();
while(!$res->EOF)
{
    $dataFromDB = array($res->fields['CODCLI'] => 
                     array(
                           "Address" => $res->fields['CIDCLI'].",".$res->fields['SIGUFS'].", USA", 
                           "Name"    => "SOMENAME")
                          );
    $address[]  = $dataFromDB;
    $res->MoveNext();
}

and the result is this:

Array
 (
   [0] => Array
      (
        [28947] => Array
            (
                [Address] => PIRIPIRI,PI,USA
                [Name] => SOMENAME
            )
      )
 )

but what i realy need is to come like this:

Array
(
  [1] => Array
    (
        [Address] => PIRIPIRI,PI,USA
        [Name] => SOMENAME
    )
)

i try some other stuffs, but nothing help me, what i'm missing?

Remove that 1st step, just do this:

$address[]  = array(
   "Address" => $res->fields['CIDCLI'].",".$res->fields['SIGUFS'].", USA", 
   "Name"    => "SOMENAME"
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM