tags:

views:

74

answers:

4

I have a arrays like this.

$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"
       )
    )
 );

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']
     )
  )
)
A: 
$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];
}
Ben Fransen
A: 
$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...

Chouchenos
A: 

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

any of these two should do the trick

ChrisR
+1  A: 

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";
Phill Pafford
@Phill Pafford Thanks for editing.I used array_merge And I got a result what I need.Is it fine?
vinothkumar
if it gives you the desired data, then use it
Phill Pafford
@Phill Pafford Ya...its gives what I exactly needs..Thanks for your answer,edits and comments..
vinothkumar