2017-03-08 78 views
0

您好我有這個巨大的數組內的值:PHP - 從數組中得到一個數組

array(14) { 
    ["imagen-profesor"]=> 
    array(8) { 
    ["id"]=> 
    string(15) "imagen-profesor" 
    ["slug"]=> 
    string(15) "imagen-profesor" 
    ["type"]=> 
    string(5) "image" 
    ["name"]=> 
    string(15) "Imagen profesor" 
    ["description"]=> 
    string(17) "Foto del profesor" 
    ["data"]=> 
    array(8) { 
     ["slug-pre-save"]=> 
     string(15) "imagen-profesor" 
     ["placeholder"]=> 
     string(0) "" 
     ["user_default_value"]=> 
     string(0) "" 
     ["repetitive"]=> 
     string(1) "0" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
     ["validate"]=> 
     array(1) { 
     ["url2"]=> 
     array(3) { 
      ["active"]=> 
      string(1) "1" 
      ["message"]=> 
      string(60) "Please enter a valid URL address pointing to the image file." 
      ["suppress_for_cred"]=> 
      bool(true) 
     } 
     } 
    } 
    ["meta_key"]=> 
    string(20) "wpcf-imagen-profesor" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["grados-academicos"]=> 
    array(8) { 
    ["id"]=> 
    string(17) "grados-academicos" 
    ["slug"]=> 
    string(17) "grados-academicos" 
    ["type"]=> 
    string(7) "wysiwyg" 
    ["name"]=> 
    string(18) "Grados académicos" 
    ["description"]=> 
    string(0) "" 
    ["data"]=> 
    array(5) { 
     ["slug-pre-save"]=> 
     string(17) "grados-academicos" 
     ["user_default_value"]=> 
     string(0) "" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(22) "wpcf-grados-academicos" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["experiencia-profesional"]=> 
    array(8) { 
    ["id"]=> 
    string(23) "experiencia-profesional" 
    ["slug"]=> 
    string(23) "experiencia-profesional" 
    ["type"]=> 
    string(7) "wysiwyg" 
    ["name"]=> 
    string(23) "Experiencia profesional" 
    ["description"]=> 
    string(46) "Por favor coloca aquí experiencia profesional" 
    ["data"]=> 
    array(5) { 
     ["slug-pre-save"]=> 
     string(23) "experiencia-profesional" 
     ["user_default_value"]=> 
     string(0) "" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(28) "wpcf-experiencia-profesional" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["areas-de-interes"]=> 
    array(8) { 
    ["id"]=> 
    string(16) "areas-de-interes" 
    ["slug"]=> 
    string(16) "areas-de-interes" 
    ["type"]=> 
    string(7) "wysiwyg" 
    ["name"]=> 
    string(18) "Áreas de interés" 
    ["description"]=> 
    string(22) "Intereses del profesor" 
    ["data"]=> 
    array(5) { 
     ["slug-pre-save"]=> 
     string(16) "areas-de-interes" 
     ["user_default_value"]=> 
     string(0) "" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(21) "wpcf-areas-de-interes" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["cursos-relevantes"]=> 
    array(8) { 
    ["id"]=> 
    string(17) "cursos-relevantes" 
    ["slug"]=> 
    string(17) "cursos-relevantes" 
    ["type"]=> 
    string(7) "wysiwyg" 
    ["name"]=> 
    string(17) "Cursos relevantes" 
    ["description"]=> 
    string(7) "Cursos " 
    ["data"]=> 
    array(5) { 
     ["slug-pre-save"]=> 
     string(17) "cursos-relevantes" 
     ["user_default_value"]=> 
     string(0) "" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(22) "wpcf-cursos-relevantes" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["articulos"]=> 
    array(8) { 
    ["id"]=> 
    string(9) "articulos" 
    ["slug"]=> 
    string(9) "articulos" 
    ["type"]=> 
    string(7) "wysiwyg" 
    ["name"]=> 
    string(10) "Artículos" 
    ["description"]=> 
    string(0) "" 
    ["data"]=> 
    array(5) { 
     ["slug-pre-save"]=> 
     string(9) "articulos" 
     ["user_default_value"]=> 
     string(0) "" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(14) "wpcf-articulos" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["areas-academicas"]=> 
    array(8) { 
    ["id"]=> 
    string(16) "areas-academicas" 
    ["slug"]=> 
    string(16) "areas-academicas" 
    ["type"]=> 
    string(6) "select" 
    ["name"]=> 
    string(18) "Áreas académicas" 
    ["description"]=> 
    string(0) "" 
    ["data"]=> 
    array(6) { 
     ["slug-pre-save"]=> 
     string(16) "areas-academicas" 
     ["options"]=> 
     array(12) { 
     ["wpcf-fields-select-option-96129381b0cc289dd28e00d98f8c15b0-1"]=> 
     array(2) { 
      ["title"]=> 
      string(23) "Análisis de decisiones" 
      ["value"]=> 
      string(1) "1" 
     } 
     ["wpcf-fields-select-option-f320b41329b42d462bd08eb7961f2c65-1"]=> 
     array(2) { 
      ["title"]=> 
      string(17) "Comercialización" 
      ["value"]=> 
      string(1) "2" 
     } 
     ["wpcf-fields-select-option-f6b63eb3926b7de2462225998e09cc13-1"]=> 
     array(2) { 
      ["title"]=> 
      string(32) "Control e información directiva" 
      ["value"]=> 
      string(1) "3" 
     } 
     ["wpcf-fields-select-option-b2610684e6f824fd687a74d3be7bcabe-1"]=> 
     array(2) { 
      ["title"]=> 
      string(21) "Dirección financiera" 
      ["value"]=> 
      string(1) "4" 
     } 
     ["wpcf-fields-select-option-d2c3f7b635105db769c4772a15d5cec2-1"]=> 
     array(2) { 
      ["title"]=> 
      string(25) "Dirección de operaciones" 
      ["value"]=> 
      string(1) "5" 
     } 
     ["wpcf-fields-select-option-f14bad56bc815fa8060ae231ccb8a217-1"]=> 
     array(2) { 
      ["title"]=> 
      string(22) "Dirección de personal" 
      ["value"]=> 
      string(1) "6" 
     } 
     ["wpcf-fields-select-option-c6114cc9883ef2a4c8d23d9985fd41fc-1"]=> 
     array(2) { 
      ["title"]=> 
      string(15) "Empresa-familia" 
      ["value"]=> 
      string(1) "7" 
     } 
     ["wpcf-fields-select-option-6378fcaa75be017d5cddec1f4c837bba-1"]=> 
     array(2) { 
      ["title"]=> 
      string(18) "Entorno económico" 
      ["value"]=> 
      string(1) "8" 
     } 
     ["wpcf-fields-select-option-48713712cd807bd0920369faaea72630-1"]=> 
     array(2) { 
      ["title"]=> 
      string(26) "Entorno político y social" 
      ["value"]=> 
      string(1) "9" 
     } 
     ["wpcf-fields-select-option-35c50a5e264b2951ccbd9a83f0d52185-1"]=> 
     array(2) { 
      ["title"]=> 
      string(13) "Factor humano" 
      ["value"]=> 
      string(2) "10" 
     } 
     ["wpcf-fields-select-option-bdac1a39ab699e74fbffd3b6a9aa85be-1"]=> 
     array(2) { 
      ["title"]=> 
      string(20) "Política de empresa" 
      ["value"]=> 
      string(2) "11" 
     } 
     ["default"]=> 
     string(10) "no-default" 
     } 
     ["validate"]=> 
     array(1) { 
     ["required"]=> 
     array(3) { 
      ["active"]=> 
      string(1) "1" 
      ["value"]=> 
      string(4) "true" 
      ["message"]=> 
      string(25) "Por favor, elige el área" 
     } 
     } 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(21) "wpcf-areas-academicas" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["calendario"]=> 
    array(8) { 
    ["id"]=> 
    string(10) "calendario" 
    ["slug"]=> 
    string(10) "calendario" 
    ["type"]=> 
    string(4) "date" 
    ["name"]=> 
    string(10) "Calendario" 
    ["description"]=> 
    string(0) "" 
    ["data"]=> 
    array(7) { 
     ["slug-pre-save"]=> 
     string(10) "calendario" 
     ["placeholder"]=> 
     string(0) "" 
     ["date_and_time"]=> 
     string(4) "date" 
     ["repetitive"]=> 
     string(1) "0" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(15) "wpcf-calendario" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["duracion"]=> 
    array(8) { 
    ["id"]=> 
    string(8) "duracion" 
    ["slug"]=> 
    string(8) "duracion" 
    ["type"]=> 
    string(8) "textarea" 
    ["name"]=> 
    string(9) "Duración" 
    ["description"]=> 
    string(0) "" 
    ["data"]=> 
    array(7) { 
     ["slug-pre-save"]=> 
     string(8) "duracion" 
     ["placeholder"]=> 
     string(0) "" 
     ["user_default_value"]=> 
     string(0) "" 
     ["repetitive"]=> 
     string(1) "0" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(13) "wpcf-duracion" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["fechas"]=> 
    array(8) { 
    ["id"]=> 
    string(6) "fechas" 
    ["slug"]=> 
    string(6) "fechas" 
    ["type"]=> 
    string(8) "textarea" 
    ["name"]=> 
    string(6) "Fechas" 
    ["description"]=> 
    string(0) "" 
    ["data"]=> 
    array(7) { 
     ["slug-pre-save"]=> 
     string(6) "fechas" 
     ["placeholder"]=> 
     string(0) "" 
     ["user_default_value"]=> 
     string(0) "" 
     ["repetitive"]=> 
     string(1) "0" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(11) "wpcf-fechas" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["contacto"]=> 
    array(8) { 
    ["id"]=> 
    string(8) "contacto" 
    ["slug"]=> 
    string(8) "contacto" 
    ["type"]=> 
    string(7) "wysiwyg" 
    ["name"]=> 
    string(8) "Contacto" 
    ["description"]=> 
    string(0) "" 
    ["data"]=> 
    array(5) { 
     ["slug-pre-save"]=> 
     string(8) "contacto" 
     ["user_default_value"]=> 
     string(0) "" 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(13) "wpcf-contacto" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["areas-academicas-2"]=> 
    array(8) { 
    ["id"]=> 
    string(18) "areas-academicas-2" 
    ["slug"]=> 
    string(18) "areas-academicas-2" 
    ["type"]=> 
    string(6) "select" 
    ["name"]=> 
    string(24) "Segunda área académica" 
    ["description"]=> 
    string(0) "" 
    ["data"]=> 
    array(5) { 
     ["slug-pre-save"]=> 
     string(18) "areas-academicas-2" 
     ["options"]=> 
     array(12) { 
     ["wpcf-fields-select-option-a84588db3f03c2837345f94adfa18588-1"]=> 
     array(2) { 
      ["title"]=> 
      string(23) "Análisis de decisiones" 
      ["value"]=> 
      string(1) "1" 
     } 
     ["wpcf-fields-select-option-5a20ef6e60591caaf5bec848cf43cec0-1"]=> 
     array(2) { 
      ["title"]=> 
      string(17) "Comercialización" 
      ["value"]=> 
      string(1) "2" 
     } 
     ["wpcf-fields-select-option-3b00b7d1d1040c63c3512a7e52446443-1"]=> 
     array(2) { 
      ["title"]=> 
      string(32) "Control e información directiva" 
      ["value"]=> 
      string(1) "3" 
     } 
     ["wpcf-fields-select-option-da90a64b9b2bf7becfbec27c9c4025da-1"]=> 
     array(2) { 
      ["title"]=> 
      string(21) "Dirección financiera" 
      ["value"]=> 
      string(1) "4" 
     } 
     ["wpcf-fields-select-option-65c40a4ea4cde81d6fb7b5bbe1c73282-1"]=> 
     array(2) { 
      ["title"]=> 
      string(25) "Dirección de operaciones" 
      ["value"]=> 
      string(1) "5" 
     } 
     ["wpcf-fields-select-option-3b7a56cdb15cef8028daf43082269339-1"]=> 
     array(2) { 
      ["title"]=> 
      string(22) "Dirección de personal" 
      ["value"]=> 
      string(1) "6" 
     } 
     ["wpcf-fields-select-option-6eded9521556a27a4cf4465c82f0a203-1"]=> 
     array(2) { 
      ["title"]=> 
      string(15) "Empresa-familia" 
      ["value"]=> 
      string(1) "7" 
     } 
     ["wpcf-fields-select-option-5102092609e13386bfadc0ed367591b7-1"]=> 
     array(2) { 
      ["title"]=> 
      string(18) "Entorno económico" 
      ["value"]=> 
      string(1) "8" 
     } 
     ["wpcf-fields-select-option-e1aadcfe82cc3389a57288a85ed45ff6-1"]=> 
     array(2) { 
      ["title"]=> 
      string(26) "Entorno político y social" 
      ["value"]=> 
      string(1) "9" 
     } 
     ["wpcf-fields-select-option-6440b6d9a60739b88dacaafae2bccaa9-1"]=> 
     array(2) { 
      ["title"]=> 
      string(13) "Factor humano" 
      ["value"]=> 
      string(2) "10" 
     } 
     ["wpcf-fields-select-option-2d081231584de301011755851f93b246-1"]=> 
     array(2) { 
      ["title"]=> 
      string(20) "Política de empresa" 
      ["value"]=> 
      string(2) "11" 
     } 
     ["default"]=> 
     string(10) "no-default" 
     } 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(23) "wpcf-areas-academicas-2" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["cargo-profesor"]=> 
    array(8) { 
    ["id"]=> 
    string(14) "cargo-profesor" 
    ["slug"]=> 
    string(14) "cargo-profesor" 
    ["type"]=> 
    string(6) "select" 
    ["name"]=> 
    string(14) "Cargo Profesor" 
    ["description"]=> 
    string(36) "Selecciona un cargo para el profesor" 
    ["data"]=> 
    array(6) { 
     ["slug-pre-save"]=> 
     string(14) "cargo-profesor" 
     ["options"]=> 
     array(5) { 
     ["wpcf-fields-select-option-2a9da69d4d39817ac2a4b687ac49dc27-1"]=> 
     array(2) { 
      ["title"]=> 
      string(18) "Director del área" 
      ["value"]=> 
      string(1) "4" 
     } 
     ["wpcf-fields-select-option-b7ae4c59b346a60a6680338c9c44c456-1"]=> 
     array(2) { 
      ["title"]=> 
      string(8) "Profesor" 
      ["value"]=> 
      string(1) "1" 
     } 
     ["wpcf-fields-select-option-51a473bf339e2669511accaa90983fb0-1"]=> 
     array(2) { 
      ["title"]=> 
      string(17) "Profesor invitado" 
      ["value"]=> 
      string(1) "2" 
     } 
     ["wpcf-fields-select-option-734e5707d3253ded0bf0d972f1c56afe-1"]=> 
     array(2) { 
      ["title"]=> 
      string(6) "Decano" 
      ["value"]=> 
      string(1) "3" 
     } 
     ["default"]=> 
     string(10) "no-default" 
     } 
     ["validate"]=> 
     array(1) { 
     ["required"]=> 
     array(3) { 
      ["active"]=> 
      string(1) "1" 
      ["value"]=> 
      string(4) "true" 
      ["message"]=> 
      string(23) "This field is required." 
     } 
     } 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(19) "wpcf-cargo-profesor" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
    ["segundo-cargo"]=> 
    array(8) { 
    ["id"]=> 
    string(13) "segundo-cargo" 
    ["slug"]=> 
    string(13) "segundo-cargo" 
    ["type"]=> 
    string(6) "select" 
    ["name"]=> 
    string(13) "Segundo cargo" 
    ["description"]=> 
    string(0) "" 
    ["data"]=> 
    array(5) { 
     ["slug-pre-save"]=> 
     string(13) "segundo-cargo" 
     ["options"]=> 
     array(5) { 
     ["wpcf-fields-select-option-30ef69a1ba17b84f26edcee1404746f4-1"]=> 
     array(2) { 
      ["title"]=> 
      string(18) "Director del área" 
      ["value"]=> 
      string(1) "1" 
     } 
     ["wpcf-fields-select-option-8b8dbd4c42d2e4d61053f442e82a88be-1"]=> 
     array(2) { 
      ["title"]=> 
      string(8) "Profesor" 
      ["value"]=> 
      string(1) "2" 
     } 
     ["wpcf-fields-select-option-862f1fbf0e317265cf544b754d6fa3f0-1"]=> 
     array(2) { 
      ["title"]=> 
      string(17) "Profesor invitado" 
      ["value"]=> 
      string(1) "3" 
     } 
     ["wpcf-fields-select-option-d49829cdb8f8aaae8af93f30f220ca86-1"]=> 
     array(2) { 
      ["title"]=> 
      string(6) "Decano" 
      ["value"]=> 
      string(1) "4" 
     } 
     ["default"]=> 
     string(10) "no-default" 
     } 
     ["custom_use"]=> 
     string(0) "" 
     ["conditional_display"]=> 
     array(0) { 
     } 
     ["disabled_by_type"]=> 
     int(0) 
    } 
    ["meta_key"]=> 
    string(18) "wpcf-segundo-cargo" 
    ["meta_type"]=> 
    string(8) "usermeta" 
    } 
} 

我只想得到這個值:決策分析,市場營銷,控制和信息政策,財務管理,「 。運營管理,人事管理,企業的家庭,經濟,政治和社會環境,人的因素,企業的政策

我的意思是裏面areas-academicas

我使用嵌套的foreach,但沒有:

foreach ($un as $key => $value) 
    { 

     if ($key === "areas-academicas") 
     { 
     echo "Llave: " . $key . " => "; 
     //echo $value; 
     foreach ($value as $key2 => $value2) 
     { 
      echo "Llave2: " . $key2 . "<br />" . "valor2: " . $value2; 

      foreach ($value2 as $key3 => $value3) 
      { 
      echo "Llave3: " . $key3 . "<br />" . "valor3: " . $value3; 
      } 
     } 
     } 

    } 

,這可能是一個簡單的方法來獲得這些價值?謝謝。

+0

array_walk_recursive – bxN5

+0

要誠實,你有一個壞的數據結構,這將是更好的,如果因此它是一個有點更容易得到處理,你可以重新設計它。是 –

回答

1

如果我不搞砸你的嵌套隨着這應該工作。如果不能解決只是foreach內的路徑。

$data = array(...); // the array you posted 

foreach ($data["areas-academicas"]["data"]["options"] as $area) { 
    echo $area["title"]; 
} 

底線是,你可以從任何級別開始迭代,你不必在上面一定要開始。

+0

這對我的作品,謝謝。 – user2580401

1

在陣列看,似乎你只能在兩個數組在頂層興趣:

$un["areas-academicas"] 
$un["areas-academicas-2"] 

然後你正在尋找特定值,數據的選擇稱號,在嵌套結構這兩個下:

$un["areas-academicas"]['data']['options'][....]['title'] 

您可以通過使用這些陣列的均勻結構可能限制你的循環迭代。但我會假設你通過頂層陣列希望環路包含「領域學術」鍵:

$titles = array(); 
foreach ($un as $key => $value){ 
    if(strpos($key, 'areas-academicas') == false){ continue; } 
    foreach($value['data']['options'] as $val){ 
     $titles[] = $val['title']; 
    } 
} 

這個循環應該收集領域學術陣列中的所有選項的標題,但概念是,依賴嵌套結構將統一爲頂級陣列中的關鍵領域學術的每個實例。希望這有助於