Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2002
    Messaggi
    378

    Impostare un foreach di un array multidimensionale

    Ciao a tutti,
    mi aiutate a impostare il foreach per stampare tutti i title contenuti nell'array [Item] ?
    Ho provato ma ad un certo punto mi sono perso:
    [PHP]
    foreach ($array as $vals) {
    foreach ($vals['ItemComponentsItemType'] as $itemComponentsItemType) {
    foreach ($itemComponentsItemType['ItemType'] as $itemType) {
    pr($itemType);
    // foreach ($itemType['ItemType']['Item'] as $item) {

    Codice PHP:
    Array
    (
        [
    0] => Array
            (
                [
    ItemComponent] => Array
                    (
                        [
    id] => 1
                        
    [title] => News
                        
    [active] => 1
                    
    )

                [
    ItemComponentsItemType] => Array
                    (
                        [
    0] => Array
                            (
                                [
    id] => 16
                                
    [item_component_id] => 1
                                
    [item_type_id] => 3
                                
    [ItemType] => Array
                                    (
                                        [
    id] => 3
                                        
    [active] => 1
                                        
    [title] => Page News
                                        
    [alias] => PageNews
                                        
    [item_render_id] => 4
                                        
    [order] => 0
                                        
    [image] => 
                                        [
    image_dir] => 
                                        [
    note] => 
                                        [
    parent_id] => 
                                        [
    lft] => 5
                                        
    [rght] => 6
                                        
    [find_limit] => 20
                                        
    [find_order] => ASC
                                        
    [item_find_order_id] => 2
                                        
    [Item] => Array
                                            (
                                                [
    0] => Array
                                                    (
                                                        [
    title] => FAQ
                                                        
    [slug] => faq
                                                        
    [id] => 16
                                                        
    [parent_id] => 106
                                                        
    [structure] => 1
                                                        
    [item_type_id] => 3
                                                    
    )

                                                [
    1] => Array
                                                    (
                                                        [
    title] => Portfolio
                                                        
    [id] => 27
                                                        
    [parent_id] => 106
                                                        
    [structure] => 1
                                                        
    [item_type_id] => 3
                                                    
    )

                                                [
    2] => Array
                                                    (
                                                        [
    title] => Viaggi
                                                        
    [id] => 92
                                                        
    [parent_id] => 106
                                                        
    [structure] => 1
                                                        
    [item_type_id] => 3
                                                    
    )

                                                [
    3] => Array
                                                    (
                                                        [
    title] => Regole del sito
                                                        
    [slug] => rules
                                                        
    [id] => 107
                                                        
    [parent_id] => 106
                                                        
    [structure] => 1
                                                        
    [item_type_id] => 3
                                                    
    )

                                            )

                                    )

                            )

                    )

            )


    Basta vivere,
    basta amare ogni momento
    e non porsi alcuna domanda
    sul momento che verrà

  2. #2
    E' un singolo valore come nell'esempio o ci sono elementi multipli?

    Se e' solo un valore da cui devi estrarre quei dati:
    Codice PHP:
    $items $array[0]['ItemComponentsItemType'][0]['ItemType']['Item'];

    foreach (
    $items as $i) {
        echo 
    $i['title'];

    altrimenti devi fare cosi':
    Codice PHP:
    foreach ($array as $a) {
        foreach (
    $a['ItemComponentsItemType'] as $component) {
            
    $items $component['ItemType']['Item'];

            foreach (
    $items as $i) {
                echo 
    $i['title'];
            }
        }

    sempre se non mi sono perso qualche livello.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2002
    Messaggi
    378
    Grazie mille funziona!
    Basta vivere,
    basta amare ogni momento
    e non porsi alcuna domanda
    sul momento che verrà

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.