php - understanding variables and scope -


edit*** question bit hard understand...let me try again.

i'm having problem understanding variables , the way execute value.

for example.

if say

$var name= 'mike'; 

then if test page nothing show because nothing on html requesting value of mike.

if did

echo $name; 

then page show mike.....

that said, if this:

$connect2db = mysqli_connect('values here'); if(!$connect2db){     die("error connecting database" . mysqli_error);}  $db_query = mysqli_query($connect2db, "insert email_list(email, firstname, lastname)                 values ('$email', '$fname', '$lname')"); 

for inserting these values form db, don't understand how connection , commands db being called , put play because me

$connect2db equals "those commands" nothing calling it. $connect2db equals literally instruction take once called play.

where on chunk of code connection being called/put play? on code block code being called action(like echo above calls $name put action display value"???.

i don't see on connect2db variable calls action/connection properties work.

like example if

pseudo

if(is true){ this.$db_query;  } 

this understand, me means if evaluates true, thing in middle..

with original first code block, variable naming , calling @ same time.

in reference to

$connect2db = mysqli_connect('values here'); 

you mention:

$connect2db equals "those commands" nothing calling it. $connect2db equals literally instruction take once called play.

that not true. mysqli_connect function, , using syntax (functionname(argument)) calls function. $connect2db used store return value function.

to sum goes on on line:

  • a call existing function called mysqli_connect made. executes function.
  • the return value function gets stored in variable named $connect2db

the rules governing assignment defined operator precedence, in case specifies function call evaluated prior assignment.

to know type of return is, 1 must @ api documentation function, , in case object (which represents connection server).


now possible have variable contain function, thought example meant. syntax of - called anonymous function, so:

$greet = function($name) {     printf("hello %s\r\n", $name); }; 

you can see instead of format:

functionname + parenthesis + argument(s) + parenthesis + semicolon

the format is:

function + parenthesis + argument(s) + parenthesis + open bracket + function definition + close bracket + semicolon

in case, variable holds function does, function has not beem executed, , execute use first format:

$greet('world'); 

note format available in php 5.3 only, prior 1 needed use create_function.


relevant links:


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -