why this function display sharma not love on browser

<?php
$a='abc';
define("h",sharma);
define("h",love);
echo h;
?>

and second

why this will show nothing on browers?
<?php 
$a='abc';
bb();
function bb()
{
	echo $a;
}
?>


and second

<?php 
$a='abc';
bb();
function bb()
{
	echo $a;
}
?>

In this section, the variable $a is local, and not defined in the global scope. When you try to reference $a inside the function, because it is not defined inside the function, nor passed as a variable TO the function, it reads that inside of the function, $a=''. Now, if you were to code this:

why this will show nothing on browers?
<?php 
$a='abc';
global $a;
bb();
function bb()
{
	echo $a;
}
?>

...the browser would print 'abc', because $a='abc' regardless of where it is called in the script.

NOTE: Unless otherwise necessary, I do not personally advocate the overuse of global.

why this function display sharma not love on browser

<?php
$a='abc';
define("h",sharma);
define("h",love);
echo h;
?>

Not sure why $a is in this example, but ok. :)

These are the differences between constants and variables:

Constants do not have a dollar sign ($) before them;
Constants may only be defined using the define() function, not by simple assignment;
Constants may be defined and accessed anywhere without regard to variable scoping rules;
Constants may not be redefined or undefined once they have been set; and
Constants may only evaluate to scalar values.

You can find the whole skinny here:

http://www.php.net/manual/en/language.constants.php

Hope this helped.

thnx 4 reply...

but after declaring that variable global it is not showing anything on my browers.

i have understand second answer.

thnx 4 reply...

but after declaring that variable global it is not showing anything on my browers.

i understand second answer.

That was a misstep on my part.

<?php 

$a='abc';

bb();

function bb() {
        global $a;
	echo $a;
}
?>

The global is called where it is needed, here inside the function.

I just so rarely use them that I forget their specifics sometimes. Sorry about that. :)

it's ok no sorry...

i got the answer... your link help me.. thankx angain

it's ok no sorry...

i got the answer... your link help me.. thankx again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.