Re: return array
| From: | Rui Cunha | Date: | Sat, 26 Jun 2004 20:38:50 +0000 |
| Subject: | Re: return array | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-34997@lists.php.net to get a copy of this message | ||
the field variable has been defined outside the function as a global var?
if not, don't forget to do it. Inside the function, the var behaves as local, unless you declare it as global.here's an example:
<?php
$x = 2;
function test_x () {
echo $x; //doesn't work because x is not global;
//but if you do something like:
global $x;
echo $x; // will print 2
}
?>
Rui Cunha
Sukanto Kho writes:
Hi All,
how to return array var from function ??
I have try that but just can't return it..
here's my code :(function to return any fields name from table)
function fields($table,$db_name)
{ $link=$this->database(); // this open the database connection
$fields = mysql_list_fields($db_name, $table, $link);
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {
$field[$i] = mysql_field_name($fields, $i);}
return $field[];
}
Thanx a lot
Sukanto