2014-04-04 53 views
0

我想從海量數組中獲得一些值,並且出現了一些問題。 我有這樣數組:從assoiavite海量數組中選擇值

array(2) { 
    [0]=> 
    array(23) { 
    ["ITEM_ID"]=> 
    int(2331) 
    ["ITEM_TYPE_ID"]=> 
    string(1) "1" 
    ["CART_ITEM_ID"]=> 
    string(0) "" 
    ["SAVED_TYPE_ID"]=> 
    string(0) "" 
    ["ITEM_NAME"]=> 
    string(17) "TEST STOCK LEVELS" 
    ["ERROR"]=> 
    string(0) "" 
    ["PROPERTIES"]=> 
    array(1) { 
     [522]=> 
     array(1) { 
     [0]=> 
     string(4) "1122" 
     } 
    } 
    ["PROPERTIES_INFO"]=> 
    array(1) { 
     [522]=> 
     array(12) { 
     ["USAGE_TYPE"]=> 
     string(1) "1" 
     ["CONTROL"]=> 
     string(7) "LISTBOX" 
     ["TYPE"]=> 
     string(1) "1" 
     ["NAME"]=> 
     string(11) "TEST OPTION" 
     ["VALUES"]=> 
     array(1) { 
      [0]=> 
      string(4) "1122" 
     } 
     ["REQUIRED"]=> 
     string(1) "1" 
     ["PARENT_PROPERTY_ID"]=> 
     string(0) "" 
     ["PARENT_VALUE_ID"]=> 
     string(0) "" 
     ["TEXT"]=> 
     array(0) { 
     } 
     ["CONTROL_PRICE"]=> 
     int(0) 
     ["ORDER"]=> 
     string(1) "1" 
     ["QUANTITY_ACTION"]=> 
     string(1) "1" 
     } 
    } 
    ["PROPERTIES_PRICE"]=> 
    float(10) 
    ["PROPERTIES_PERCENTAGE"]=> 
    int(0) 
    ["PROPERTIES_BUYING"]=> 
    int(0) 
    ["PROPERTIES_DISCOUNT"]=> 
    int(0) 
    ["PROPERTIES_MORE"]=> 
    string(1) "0" 
    ["COMPONENTS"]=> 
    array(0) { 
    } 
    ["QUANTITY"]=> 
    int(11) 
    ["TAX_FREE"]=> 
    string(1) "0" 
    ["DISCOUNT"]=> 
    int(1) 
    ["BUYING_PRICE"]=> 
    string(0) "" 
    ["PRICE_EDIT"]=> 
    string(1) "0" 
    ["PRICE"]=> 
    string(5) "10.00" 
    ["CHECK_PRICE"]=> 
    float(20) 
    ["MAX_ITEM_DISCOUNT"]=> 
    float(20) 
    ["CART_PRICE"]=> 
    float(20) 
    } 
    [1]=> 
    array(23) { 
    ["ITEM_ID"]=> 
    int(2331) 
    ["ITEM_TYPE_ID"]=> 
    string(1) "1" 
    ["CART_ITEM_ID"]=> 
    string(0) "" 
    ["SAVED_TYPE_ID"]=> 
    string(0) "" 
    ["ITEM_NAME"]=> 
    string(17) "TEST STOCK LEVELS" 
    ["ERROR"]=> 
    string(0) "" 
    ["PROPERTIES"]=> 
    array(1) { 
     [522]=> 
     array(1) { 
     [0]=> 
     string(4) "1123" 
     } 
    } 
    ["PROPERTIES_INFO"]=> 
    array(1) { 
     [522]=> 
     array(12) { 
     ["USAGE_TYPE"]=> 
     string(1) "1" 
     ["CONTROL"]=> 
     string(7) "LISTBOX" 
     ["TYPE"]=> 
     string(1) "1" 
     ["NAME"]=> 
     string(11) "TEST OPTION" 
     ["VALUES"]=> 
     array(1) { 
      [0]=> 
      string(4) "1123" 
     } 
     ["REQUIRED"]=> 
     string(1) "1" 
     ["PARENT_PROPERTY_ID"]=> 
     string(0) "" 
     ["PARENT_VALUE_ID"]=> 
     string(0) "" 
     ["TEXT"]=> 
     array(0) { 
     } 
     ["CONTROL_PRICE"]=> 
     int(0) 
     ["ORDER"]=> 
     string(1) "1" 
     ["QUANTITY_ACTION"]=> 
     string(1) "1" 
     } 
    } 
    ["PROPERTIES_PRICE"]=> 
    float(20) 
    ["PROPERTIES_PERCENTAGE"]=> 
    int(0) 
    ["PROPERTIES_BUYING"]=> 
    int(0) 
    ["PROPERTIES_DISCOUNT"]=> 
    int(0) 
    ["PROPERTIES_MORE"]=> 
    string(1) "0" 
    ["COMPONENTS"]=> 
    array(0) { 
    } 
    ["QUANTITY"]=> 
    int(5) 
    ["TAX_FREE"]=> 
    string(1) "0" 
    ["DISCOUNT"]=> 
    int(1) 
    ["BUYING_PRICE"]=> 
    string(0) "" 
    ["PRICE_EDIT"]=> 
    string(1) "0" 
    ["PRICE"]=> 
    string(5) "10.00" 
    ["CHECK_PRICE"]=> 
    float(30) 
    ["MAX_ITEM_DISCOUNT"]=> 
    float(30) 
    ["CART_PRICE"]=> 
    float(30) 
    } 
} 

之前循環該陣列中,我接收一些PROPERTY_ID(1123例如)。 我需要檢查,如果這PROPERTY_ID(在我的情況下,1122)這個元素相匹配

["PROPERTIES"]=> 
    array(1) { 
     [522]=> 
     array(1) { 
     [0]=> 
     string(4) "1122" 
     } 
    } 

然後選擇它的數量屬性(在我的情況下,這個元素)

["QUANTITY"]=> 
int(11) 

的問題是確定從哪個數組中選擇這個屬性,因爲首先我需要將我收到的值與數組中的現有值進行比較(在我的例子中爲1122)。

+2

'str_replace函數($ thisPost, '海量', '陣')'...? Babelfish平臺? – deceze

+0

對不起))現在,編輯 – volodymyr3131

+0

我沒有得到它,你可以進一步指定你的問題 – worenga

回答

1

我認爲你可以用更好的組織陣列來做得更快。因爲這是我會做一個循環。

類似的東西:

$quantity = 0; 
$which_array = -1; 
foreach($massive as $key=>$value){ 

    if(isset($value['PROPERTIES_INFO'])){ 
    $copy_properties = $value['PROPERTIES_INFO']; 
    $property_first = reset($copy_properties); 
    $id_property = key($property_first); 
    if($id_property == $what_id_you_are_looking_for){ 
     $quantity = $value['QUANTITY'];//delete one of this 
     //or I don't know wich quantity you want so I put them both 
     $quantity = $value['PROPERTIES_INFO'][$id_property ]['QUANTITY_ACTION'];//delete one of this 
     $which_array = $key; 
     break; 
    } 
    } 
} 
+0

此代碼告訴我空值$量,不幸的是( – volodymyr3131

+0

)如果你複製粘貼的這段代碼$ quantity不能爲null,加上你必須設置$ what_id_you_are_looking_for = //類似1122的東西才能工作 – Su4p