Hy I have code below, I wanna return value array with function :
<?php
include "config/koneksi.php";
//script1
$fetch1 = mysqli_query($conn, "SELECT * FROM orders_temp");
$array = array();
while($row = mysqli_fetch_assoc($fetch1)){
$array[] = $row[id_orders_temp];
}
echo "script1: ";
print_r($array);
echo "<br>";
//script2
function cart(){
$array1= array();
$fetch2 = mysqli_query($conn,"SELECT * FROM orders_temp");
while ($r=mysqli_fetch_assoc($fetch2)) {
$array1[] = $r[id_orders_temp];
}
return $array1;
}
$cart1 = cart();
echo "script2 : ";
print_r($cart1);
?>
and the result :
script1: Array ( [0] => 150 [1] => 151 )
script2 : Array ( )
there's no problem if I print_r array without function, but when I used function as above, I got blank array( ). How can I get array value with function ?