- Home
- Categorie
- Coding e Sistemistica
- Coding
- funzione php
- 
							
							
							
							
							funzione phpBuongiorno a tutti, una domanda forse banale: ho una funzione: [PHP] 
 public function slideshow_homepage() {
 $array_articolo = array();
 $query_articolo = mysql_query("SELECT * FROM wp_posts WHERE post_status = 'publish' AND post_type = 'post'");
 while ($row = mysql_fetch_assoc($query_articolo)):
 $array_articolo[] = array(
 "post_title" => $row['post_title'],
 "post_date" => $row['post_date'],
 "post_content" => $row['post_content'],
 "post_author" => $row['post_author']
 );
 endwhile;$array_autore = array(); 
 $query_autore = mysql_query("SELECT * FROM wp_usermeta WHERE meta_key = 'first_name' OR meta_key = 'last_name'");
 while ($row = mysql_fetch_assoc($query_autore)):
 $array_autore[] = array(
 "meta_value" => $row['meta_value'],
 "user_id" => $row['user_id']
 );
 endwhile;
 }
 [/PHP]vorrei poter accedere agli array: $array_articolo e $array_autore fuori dalla funzione, per poi ciclarli con dei foreach; è possibile? ringrazio in anticipo 
 buona giornata
 
- 
							
							
							
							
							
Intendi poter stampare a video l'array fuori dalla funzione? Io avevo fatto una cosa del genere: [PHP] public function slideshow_homepage() { 
 $array_articolo = array();
 $query_articolo = mysql_query("SELECT * FROM wp_posts WHERE post_status = 'publish' AND post_type = 'post'");
 while ($row = mysql_fetch_assoc($query_articolo)):
 $array_articolo[] = array("post_title" => $row['post_title'],"post_date" => $row['post_date'],"post_content" => $row['post_content'],"post_author" => $row['post_author']);
 endwhile;
 $array_autore = array();$query_autore = mysql_query("SELECT * FROM wp_usermeta WHERE meta_key = 'first_name' OR meta_key = 'last_name'");
 while ($row = mysql_fetch_assoc($query_autore)):
 $array_autore[] = array("meta_value" => $row['meta_value'],"user_id" => $row['user_id']);
 endwhile;//Imposta due variabili globali contenti l'array $GLOBALS['articolo'] = $array_articolo 
 $GLOBALS['autore'] = $array_articolo} 
 //crei la funzione che consente di ciclare e stampare il contenuto dell'arrayfunction stampa($array) 
 {
 foreach($array as $arr)
 {
 echo $arr;
 }
 }// stampi il contenuto dell'array function slideshow_homepage(); 
 stampa($articolo);
 stampa($autore);[/PHP] Fammi sapere se funziona 
 
- 
							
							
							
							
							si funziona grazie mille! 