开发者

Push multidimensional arrays into array?

I have a arrays like this.

$pahrmacyid=array(
  "Identification"开发者_StackOverflow=>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"
       )
    )
 );

I want to push this arrays into another array?Is it possible? I need a result like this:

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


It's simple since you have all the array's. Here are a couple of ways to merging all the array's into one multidimensional array.

Example 1:

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

Example 2:

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

Example 3:

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


$result[] = $pahrmacyid;

And if you have multiple $pahrmacyid-arrays you can add it in a loop.

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


$result[] = $pahrmacyid;

You may want to initilize it before with

$result = array();

And I didn't try but maybe the shortcut

$result = array($pahrmacyid); 

works...


array_push($result, $pahrmacyid)
or
$result[] = $pahrmacyid

any of these two should do the trick

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜