Php 将多维数组推入数组?

Php 将多维数组推入数组?,php,arrays,Php,Arrays,我有一个这样的数组 $pahrmacyid=array( "Identification"=>array( "ID"=>array( "IDValue"=>$_GET['pharmacyid'], "IDQualifier"=>"D3" ) ) ); $storename=array( "StoreName"=>$_GET['storename'] ); $pharmacyaddress=

我有一个这样的数组

$pahrmacyid=array(
  "Identification"=>array(
     "ID"=>array(
        "IDValue"=>$_GET['pharmacyid'],
        "IDQualifier"=>"D3"
      )
    )
);

$storename=array(
   "StoreName"=>$_GET['storename']
);


$pharmacyaddress=array(
   "Address"=>array(
      "AddressLine1"=>$_GET['paddress'],
      "City"=>$_GET['pCity'],
      "State"=>$_GET['pState'],
      "ZipCode"=>$_GET['pZipCode']
    )
 );


$communicationnumber=array(
   "CommunicationNumbers"=>array(
      "Communication"=>array(
         "Number"=>$_GET['pCommunicationNumbers'],
         "Qualifier"=>"TE"
       )
    )
 );
我想把这个数组放到另一个数组中?可能吗? 我需要这样的结果:

$result=array(
   array("Identification"=>array(
      "ID"=>array(
         "IDValue"=>$_GET['pharmacyid'],"IDQualifier"=>"D3"
      )
   )
 ),
 "StoreName"=>$_GET['storename'],array(
    "Address"=>array(
       "AddressLine1"=>$_GET['paddress'],
       "City"=>$_GET['pCity'],
       "State"=>$_GET['pState'],
       "ZipCode"=>$_GET['pZipCode']
    )
 ),
 array(
    "Address"=>array(
       "AddressLine1"=>$_GET['paddress'],
       "City"=>$_GET['pCity'],
       "State"=>$_GET['pState'],
       "ZipCode"=>$_GET['pZipCode']
     )
  )
)
如果有多个$pahrmacyid数组,可以将其添加到循环中

$result = array();
for($i = 0; $i < count($sourceArray); $i++)
{
   $result[] = $sourceArray[$i];
}
$result=array();
对于($i=0;$i
您可能希望在使用之前初始化它

$result = array();
我没有尝试,但也许是捷径

$result = array($pahrmacyid); 
工作…

数组\u推送($result,$pahrmacyid)


$result[]=$pahrmacyid


这两种方法中的任何一种都应该起作用,因为你拥有了所有的数组,所以很简单。以下是将所有数组合并为一个多维数组的两种方法

例1:

$example1arr = array(
                 $pahrmacyid, 
                 $storename, 
                 $pharmacyaddress, 
                 $communicationnumber
               );
echo "Example 1: <pre>".print_r($example1arr,true)."</pre><br />\n";
$example1arr=array(
$pahrmacyid,
$storename,
$pharmacyaddress,
$communicationnumber
);
echo“示例1:”.print\r($example1arr,true)。“
\n”;
例2:

$example3arr = Array();
array_push(
   $example3arr,
   $pahrmacyid,
   $storename,
   $pharmacyaddress,
   $communicationnumber
);
echo "Example 3: <pre>".print_r($example3arr,true)."</pre><br />\n";
$example2arr[]=$pahrmacyid;
$example2arr[]=$storename;
$example2arr[]=$pharmacyaddress;
$example2arr[]=$communicationnumber;
echo“示例2:”.print\r($example2arr,true)。“
\n”;
例3:

$example3arr=Array();
阵列推送(
$example3arr,
$pahrmacyid,
$storename,
$pharmacyaddress,
$communicationnumber
);
echo“示例3:”.print\r($example3arr,true)。“
\n”;
感谢您的编辑。我使用了array\u merge,得到了我需要的结果。可以吗?如果它提供了所需的数据,请使用它
$example1arr = array(
                 $pahrmacyid, 
                 $storename, 
                 $pharmacyaddress, 
                 $communicationnumber
               );
echo "Example 1: <pre>".print_r($example1arr,true)."</pre><br />\n";
$example2arr[] = $pahrmacyid;
$example2arr[] = $storename;
$example2arr[] = $pharmacyaddress;
$example2arr[] = $communicationnumber;
echo "Example 2: <pre>".print_r($example2arr,true)."</pre><br />\n";
$example3arr = Array();
array_push(
   $example3arr,
   $pahrmacyid,
   $storename,
   $pharmacyaddress,
   $communicationnumber
);
echo "Example 3: <pre>".print_r($example3arr,true)."</pre><br />\n";