I want to get the variable $place from function getaddress and pass开发者_如何学编程 the value to function breakintostrings. It seems i cant get the variable $place.
<?php
$username ="1224hammer";
getaddress ($username);
function getaddress($username)
{
$place = row['place'];
function format_address($record)
{
function breakintostrings($x,$y,$z)
}
breakintostrings($place,"$y","$z")
}
?>
Create the variable $place
outside of your getaddress
function and import it into your breakintostrings
function using the global
keyword:
$place = '';
function getaddress($username)
{
$place = row['place'];
}
function breakintostrings($x,$y,$z)
global $place;
// more code
}
You can get the value by returning the variable $place with the return statement, but please, dont nest your functions. Please
Don't nest your functions like that. Instead, try something like this:
function getaddress($username){
return row['place']; // What is row?
}
function breakintostrings($address,$y,$z){
// do whatever
}
$address = getaddress($username);
breakintostrings($address,"$y","$z");
精彩评论