2016-10-19 69 views
0

我的數據庫中有一個序列化字段。我可以得到這個字段的內容並將其反序列化,但是我不確定如何獲得這些字段的某些值。我最終需要從數據中獲得每個項目和價值的foreach。從非序列化數據中獲取值

在下面的例子中,我需要能夠得到如下:

主要圖片替換: BGL_Burhill_People_AndyHiseman_300dpi_Super尺寸-14.JPG免費: 比較文本引用代碼:代碼文本

我需要將標籤作爲一個變量,並將該值作爲另一個foreach中的值。這些標籤和值是可變的,所以我不能通過他們的標籤手動獲取這些數據。

array (
    0 => 
    array (
    'mode' => 'builder', 
    'cssclass' => '', 
    'hidelabelinorder' => '', 
    'hidevalueinorder' => '', 
    'element' => 
    array (
     'type' => 'radio', 
     'rules_type' => 
     array (
     'Reprint_0' => 
     array (
      0 => '', 
     ), 
     'Edit Artwork_1' => 
     array (
      0 => '', 
     ), 
    ), 
     '_' => 
     array (
     'price_type' => '', 
    ), 
    ), 
    'name' => '', 
    'value' => 'Edit Artwork', 
    'price' => '', 
    'section' => '58073632e582b5.35893028', 
    'section_label' => '', 
    'percentcurrenttotal' => 0, 
    'currencies' => 
    array (
    ), 
    'price_per_currency' => 
    array (
     'GBP' => '', 
    ), 
    'quantity' => 1, 
    'multiple' => '1', 
    'key' => 'Edit Artwork_1', 
    'use_images' => '', 
    'changes_product_image' => '', 
    'imagesp' => '', 
    'images' => '', 
), 
    1 => 
    array (
    'mode' => 'builder', 
    'cssclass' => '', 
    'hidelabelinorder' => '', 
    'hidevalueinorder' => '', 
    'element' => 
    array (
     'type' => 'radio', 
     'rules_type' => 
     array (
     'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-14.JPG_0' => 
     array (
      0 => '', 
     ), 
     'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-21.JPG_1' => 
     array (
      0 => '', 
     ), 
     'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-77.JPG_2' => 
     array (
      0 => '', 
     ), 
    ), 
     '_' => 
     array (
     'price_type' => '', 
    ), 
    ), 
    'name' => 'Main Image Replacement', 
    'value' => 'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-14.JPG', 
    'price' => '', 
    'section' => '58073632e582d2.46631826', 
    'section_label' => 'Main Image Replacement', 
    'percentcurrenttotal' => 0, 
    'currencies' => 
    array (
    ), 
    'price_per_currency' => 
    array (
     'GBP' => '', 
    ), 
    'quantity' => 1, 
    'multiple' => '1', 
    'key' => 'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-14.JPG_0', 
    'use_images' => 'images', 
    'changes_product_image' => '', 
    'imagesp' => '', 
    'images' => 'http://burhill.immaculate.co.uk/wp-content/uploads/2016/10/BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-14-150x150.jpg', 
), 
    2 => 
    array (
    'mode' => 'builder', 
    'cssclass' => 'col-6', 
    'hidelabelinorder' => '', 
    'hidevalueinorder' => '', 
    'element' => 
    array (
     'type' => 'textfield', 
     'rules_type' => 
     array (
     0 => 
     array (
      0 => '', 
     ), 
    ), 
     '_' => 
     array (
     'price_type' => '', 
    ), 
    ), 
    'name' => 'Complimentary', 
    'value' => 'Comp Text', 
    'price' => '', 
    'section' => '58073632e582f4.32183997', 
    'section_label' => 'Complimentary', 
    'percentcurrenttotal' => 0, 
    'currencies' => 
    array (
    ), 
    'price_per_currency' => 
    array (
    ), 
    'quantity' => 1, 
), 
    3 => 
    array (
    'mode' => 'builder', 
    'cssclass' => 'col-6', 
    'hidelabelinorder' => '', 
    'hidevalueinorder' => '', 
    'element' => 
    array (
     'type' => 'textfield', 
     'rules_type' => 
     array (
     0 => 
     array (
      0 => '', 
     ), 
    ), 
     '_' => 
     array (
     'price_type' => '', 
    ), 
    ), 
    'name' => 'Quote Code', 
    'value' => 'Code Text', 
    'price' => '', 
    'section' => '58073632e58317.46363272', 
    'section_label' => 'Quote Code', 
    'percentcurrenttotal' => 0, 
    'currencies' => 
    array (
    ), 
    'price_per_currency' => 
    array (
    ), 
    'quantity' => 1, 
), 
) 
+2

不清楚你在問什麼。而你的陣列看起來很混亂,似乎沒有系統的安排。使其可讀。 –

+0

歡迎來到StackOverflow。不幸的是,由於數組包含可變數據,除了遍歷所有數據之外,沒有其他解決方法,除非您找到所需數據。你還沒有發佈任何代碼,所以你不清楚你嘗試了什麼,或者你面臨什麼問題或錯誤。儘可能具體,因爲它會導致更好的答案。 –

回答

0
foreach($your_array as $key => $value) { 
    $your_value = $value['value']; 
    $your_label = $value['section_label']; 
} 

這應該給你,只要我得到了正確的鍵那裏工作。