You are here: Re: global variable in function « PHP Programming Language « IT news, forums, messages
Re: global variable in function

Posted by Andy Hassall on 05/14/05 19:08

On 14 May 2005 08:50:03 -0700, "Japhy" <japhyrider2005@yahoo.com> wrote:

>Hello, I'm a newbie using PHP. Having some trouble using a variable
>within a function.
>
>I use some mysql code to assign a value to $myvariable.
>I verify that it is getting the value with an echo.
>
>Inside a function (in the same php file), I declare :
>global $myvariable ;
>However, $myvariable has lost it's value.
>
>Is there a php setting I need to change to get this to work?

No, there aren't any that affect normal global variables.

Post a short example demonstrating your problem. Cut it down as far as you
can, so it's still runnable but shows the issue. (Often this process helps you
find the problem yourself).

Are you doing something like:

<?php
$myvariable = 'x';
echo $myvariable;

function f()
{
global $myvariable;
echo $myvariable;
}
?>

Does this not give the expected result on your system?

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация