2017-02-17 282 views
-1

我願推動本:推陣列到另一個陣列PHP

"serialNumber" => $serial, 

$ postArray的內部產品陣列和

"note" => array(
        "text" => $note 
       ), 

reservationDate在$ postArray之前。

$postArray = array(
       "reservationDate" => $timeData, 
       "emailLanguageCode" => "it_it", 
       "shipToCode" => $_POST['ship'], 
       "customer" => array(
        "firstName" => $_POST['firstName'], 
        "lastName" => $_POST['lastName'], 
        "emailId" => $_POST['emailId'], 
        "phoneNumber" => $_POST['phoneNumber'], 
        "address" => array(
         "addressLine1" => $_POST['addressLine1'], 
         "city" => $_POST['city'], 
         "state" => $_POST['state'], 
         "country" => $_POST['country'], 
         "postalCode" => $_POST['postalCode'] 
        ) 
       ), 
       "product" => array(
        "productCode" => $_POST['productCode'], 
        "issueReported" => $_POST['issueReported'] 
       ) 
      ); 

,並導致我想:

$postArray = array(
       "note" => array(
        "text" => $note 
       ), 
       "reservationDate" => $timeData, 
       "emailLanguageCode" => "it_it", 
       "shipToCode" => $_POST['ship'], 
       "customer" => array(
        "firstName" => $_POST['firstName'], 
        "lastName" => $_POST['lastName'], 
        "emailId" => $_POST['emailId'], 
        "phoneNumber" => $_POST['phoneNumber'], 
        "address" => array(
         "addressLine1" => $_POST['addressLine1'], 
         "city" => $_POST['city'], 
         "state" => $_POST['state'], 
         "country" => $_POST['country'], 
         "postalCode" => $_POST['postalCode'] 
        ) 
       ), 
       "product" => array(
        "serialNumber" => $serial, 
        "productCode" => $_POST['productCode'], 
        "issueReported" => $_POST['issueReported'] 
       ) 
      ); 

我嘗試這樣做:

array_push($postArray["product"][],$numeroSerie); 

請幫助。

+0

https://secure.php.net/array_unshift –

回答

0

只需簡單地做到這一點

$postArray['product']['serialNumber'] = $serial; 
+0

非常感謝! – Leon

0

做第一個數組是要在產品陣列使用後array_merge

$postArray1 = array(
       "note" => array(
        "text" =>15 
       )); 



$postArray = array(
       "reservationDate" =>1, 
       "emailLanguageCode" => 2, 
       "shipToCode" => 3, 
       "customer" => array(
        "firstName" => 4, 
        "lastName" => 5, 
        "emailId" => 6, 
        "phoneNumber" => 7, 
        "address" => array(
         "addressLine1" => 8, 
         "city" =>9, 
         "state" => 10, 
         "country" => 11, 
         "postalCode" => 12 
        ) 
       ), 
       "product" => array(
        "productCode" => 13, 
        "issueReported" => 14 
       ) 
      ); 


array_merge($postArray1,$postArray); 
0

這兩條線,

$postArray['product'] = $serial + $postArray['product']; 
$postArray = $numeroSerie + $postArray ; 

該陣列就是這樣,

+運營商給予陣列和場外聯合將滿足您的要求。

試試看,這會起作用。

0

很簡單,添加此兩個線路代碼:

// insert "serialNumber" into "product" array 
$postArray['product']['serialNumber'] = $serial; 

// insert "note" into begining array element 
$postArray = array('note'=>array("text" => $note))+$postArray; 
0

你試試這個,我認爲它的工作的罰款。

$data=array("note" => array("text" => $note)); 
$postArray= array_merge($data,$postArray); 
$postArray["product"]=array_merge(array("serialNumber"=> $serial),$postArray["product"]);