Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    arrayIterator e cachingItinerator

    Sapete spiegarmi a cosa servono questi due oggetti in questo codice?

    Codice PHP:
    <?php

        
    // an array items to insert
        
    $array = array( 'dingo'       => 'A native dog',
                
    'wombat'      => 'A native marsupial',
                
    'platypus'    => 'A native monotreme',
                
    'koala'       => 'A native Phascolarctidae'
                
    );

        
    // begin the sql statement
        
    $sql "INSERT INTO test_table (name, description ) VALUES ";

        
    // this is where the magic happens
        
    $it = new ArrayIterator$array );

        
    // a new caching iterator gives us access to hasNext()
        
    $cit = new CachingIterator$it );

        
    // loop over the array
        
    foreach ( $cit as $value )
        {
            
    // add to the query
            
    $sql .= "('".$cit->key()."','" .$cit->current()."')";
            
    // if there is another array member, add a comma
            
    if( $cit->hasNext() )
            {
                
    $sql .= ",";
            }
        }


        
    // now we can use a single database connection and query
        
    $conn mysql_connect('db_user''db_password' );
        
    mysql_select_db'test_db'$conn );
        
    mysql_query$sql$conn );

    ?>

  2. #2
    http://php.net/manual/en/class.arrayiterator.php
    http://php.net/manual/en/class.cachingiterator.php

    le due pagine del manuale, intanto..

    Dai commenti del codice si capisce come funziona, cosa non ti è chiaro?
    Questa volta, più che un voto.. è favoreggiamento.

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 © 2025 vBulletin Solutions, Inc. All rights reserved.