The purpose of this tutorial is to explain how to return and array from a function, which will become part of another array. With PHP, you can return a string or array from a function. The string or array that is returned can become combined into another array.
<?php include('connect.inc'); $db=public_db_connect(); $count = 0; function get_data($var1,$date){ global $db; $my_values[] = $var1.",".$date; return $my_values; //return an array } $command = "SELECT DISTINCT id, email FROM table_sort WHERE id IN (1,2,3,4,5,6,7) ORDER BY id ASC "; $result = mysqli_query($db, $command); while($row = mysqli_fetch_assoc($result)) { $var1 = $row['id']; $command2= "SELECT min(date) as date FROM table_sort WHERE id ='$var1' ORDER BY id ASC"; $result2 = mysqli_query($db, $command2); while($row2 = mysqli_fetch_assoc($result2)){ $date = $row2['date']; echo $var1."-".$date."<br/>"; $get_data = get_data($var1,$date); $my_array[] = $get_data; } } print_r($my_array); foreach ($my_array as $key => $value) { $value = implode(",",$value); echo "<br/>".$key."-".$value; $value2 = str_replace(",","-",$value); echo "<br/>".$value2; } ?>
© 2018 ALL Rights Reserved | Sitemap
Vancouver | North Vancouver | Burnaby | Richmond | Coquitlam | Port Coquitlam | Surrey | Langley | Maple Ridge | Mission | Abbotsford | Kamloops | Kelowna | Victoria | Squamish | Whistler | Pemberton