简体   繁体   中英

PHP function not accepting variable

i have a simple function to display some html.

function is included in the corefunctions.php file.

I call the function and pass a word to it, but nothing gets passed. Shows up as blank. What am i doing wrong?

function showCities($pagetype) {
echo "pagetypeis: ".$pagetype;

//more code

}

I call the function from another file like this

$pagetype = "places";
showCities($pagetype);

All i see on the screen is 'pagetypeis:'

Thanks

This works just fine: (see it on tehplayground )

function showCities($pagetype) {
    echo "pagetypeis: ".$pagetype;
}

$pagetype = "places";

showCities($pagetype); #=> pagetypeis: places

In your function, try var_dump

function showCities($pagetype) {
    var_dump($pagetype);
}

What do you see?

It works for me here: http://codepad.org/vBALy4Yj

This is why it's good to use an IDE. If it were a misspelling, usually the IDE would warn you about it before even running the code. I recommend Eclipse or Zend Studio for Eclipse .

I guess the next thing I would check for is multiple definitions of function showCities() .

Try set error level to see notices.

error_reporting(E_ALL);

May be you've mispelled variable name, eg "a" in $pagetype is cyrillic "a", not latin?

必须是其他代码,对我来说效果很好,请在此处查看

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM