2011-11-07 57 views
1

我有一個數組$結果而我做了數組的print_r的,並得到了這個...製作另一個數組PHP

Array ([0] => 
      Array ([invoiceid] => 992 [client] => www [invoicedeliverymethod] => email [date] => 2011-11-04 [enddate] => 2011-10-31 23:59:59 [total] => 103.00 [remainingbalance] => 0.00 [ispaid] => Yes [isagentpaid] => No [datedistributed] => 2011-11-04 [invoicedcontact] => 1) 
     [1] => 
      Array ([invoiceid] => 991 [client] => www [invoicedeliverymethod] => email [date] => 2011-11-04 [enddate] => 2011-09-30 23:59:59 [total] => 103.00 [remainingbalance] => 0.00 [ispaid] => Yes [isagentpaid] => No [datedistributed] => Not distributed [invoicedcontact] => 1) 
     [2] => Array ([invoiceid] => 988 [client] => Sylvester Services [invoicedeliverymethod] => email [date] => 2011-11-04 [enddate] => 2011-10-31 23:59:59 [total] => 16687.83 [remainingbalance] => -14527.00 [ispaid] => No [isagentpaid] => No [datedistributed] => Not distributed [invoicedcontact] => 1) 
     [3] => Array ([invoiceid] => 987 [client] => Colony Holland Lumber [invoicedeliverymethod] => email [date] => 2011-11-04 [enddate] => 2011-10-31 23:59:59 [total] => 8345.39 [remainingbalance] => -8245.39 [ispaid] => No [isagentpaid] => No [datedistributed] => Not distributed [invoicedcontact] => 1) 
) 

我所試圖做的是使剛剛[invoiceid]數組我對PHP很陌生,任何幫助信息都很棒!由於

+4

用戶請嘗試並接受你的一些答案。 – Mob

+0

爲什麼?你所做的只是複製你已經擁有的信息。 – symcbean

回答

0
foreach ($results as $r){ 
    $new_array[] = $r['invoiced']; 
} 
1
$invoicedIds = array(); 
foreach ($results as $result) { 
    $invoicedIds[] = $result['invoiceid']; 
} 
1

很簡單...

$invoice_array = null; 

foreach ($original_complex_array as $id => $elements){ 
$invoice_array[$id] = $elements['invoiceid']; 
} 

所以,你知道哪個元素ID(不管它是什麼)匹配invoiceid。

0
<?php 
$invoiceIDArray=array(); 
foreach ($bigArray as $subArray) 
{ 
    $invoiceIDArray[]=$subArray['invoiceid']; 
} 

echo print_r($invoiceIDArray,true)."\n"; 
?> 

上面通過所有emcompassing數組來訪問子數組。然後,它只是把每個invoiceid到另一個陣列

+0

真棒謝謝! – user979331

+1

請接受你的問題的答案之一 - 你還沒有接受。乾杯 – DaveyBoy

0

如果invoiceid始終是每個子陣列的第一個元素,你可以這樣做:

$invoice_ids = array_map('current',$array); 
相關問題