2010-09-28 120 views
1

我有一个这样的数组。将多维数组推入数组中?

$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'] 
    ) 
) 
) 

回答

0
$result[] = $pahrmacyid; 

如果你有多个$ pahrmacyid阵列,你可以在一个循环中添加。

$result = array(); 
for($i = 0; $i < count($sourceArray); $i++) 
{ 
    $result[] = $sourceArray[$i]; 
} 
0
$result[] = $pahrmacyid; 

您可能希望与

$result = array(); 

之前用来初始化它,我没有尝试,但也许快捷

$result = array($pahrmacyid); 

作品...

0

array_push($result, $pahrmacyid)

$result[] = $pahrmacyid

任何这两个应该做的伎俩

3

很简单,因为你把所有的数组。这里有几种将所有数组合并成一个多维数组的方法。

例1:

$example1arr = array(
       $pahrmacyid, 
       $storename, 
       $pharmacyaddress, 
       $communicationnumber 
       ); 
echo "Example 1: <pre>".print_r($example1arr,true)."</pre><br />\n"; 

例2:

$example2arr[] = $pahrmacyid; 
$example2arr[] = $storename; 
$example2arr[] = $pharmacyaddress; 
$example2arr[] = $communicationnumber; 
echo "Example 2: <pre>".print_r($example2arr,true)."</pre><br />\n"; 

例3:

$example3arr = Array(); 
array_push(
    $example3arr, 
    $pahrmacyid, 
    $storename, 
    $pharmacyaddress, 
    $communicationnumber 
); 
echo "Example 3: <pre>".print_r($example3arr,true)."</pre><br />\n"; 
+0

感谢editing.I使用array_merge而且我得到的结果是什么我need.Is它很好吗? – svk 2010-09-29 04:43:17

+0

如果它给你所需的数据,然后使用它 – 2010-09-29 13:15:40

+0

雅...它给我我需要..谢谢你的回答,编辑和评论.. – svk 2010-10-04 10:04:55