php - Return some values with PDO in function -
i using pdo values of table : (table name ban)
id word 1 1 2 2 3 3 4 4
my function :
function retbans() { global $connect; $result = $connect->prepare("select * ban"); $result->execute(); $a = array(); while ($row = $result->fetch(pdo::fetch_assoc)){ $a = $row['word'].","; } return $a; }
and in main php file, wanted them code :
$a = array(); $a = retbans(); $b = explode(",",$a); print_r($b);
i wanted have :
array { [0] => 1 [1] => 2 [2] => 3 [3] => 4 }
but , return , print_r last value (four) in array.
how can them said ?
use instead -
$a = ''; while ($row = $result->fetch(pdo::fetch_assoc)){ $a .= $row['word'].","; }
then, can use explode
function
$a = retbans(); $b = explode(",",$a); echo "<pre>"; print_r($b);
Comments
Post a Comment