0

This is really basic PHP. Can someone tell me why this does not work and what I need to do to make it work.

<?php
$test_var=12;
proc_scrn($test_var);

proc_scrn($local_pid)
{
echo "tp12",$local_pid ;
}
?>
5
  • 1
    Declare the function before the call ? Commented Nov 2, 2011 at 11:59
  • +1, try adding function before proc_scrn. And I am not sure if the echo-part will work. Try changing it to echo "tp12".$local_pid; Commented Nov 2, 2011 at 11:59
  • 1
    @Nanocom Functions do not need to be declared before being called Commented Nov 2, 2011 at 12:02
  • @OptimusCrime That echo statement is fine and is actually faster than concatenation Commented Nov 2, 2011 at 12:02
  • 1
    There's no need to define function before its called .. Commented Nov 2, 2011 at 12:04

3 Answers 3

5

Well, you haven't actually created a function there. This would work:

<?php
$test_var=12;
proc_scrn($test_var);

function proc_scrn($local_pid='')
{
echo "tp12: ".$local_pid;
}
?>
Sign up to request clarification or add additional context in comments.

Comments

2
function proc_scrn($local_pid)
{
// something
}

PHP- User-defined functions

1 Comment

a perfect answer with no offtopic chatter.
0

Pretty simple

<?php 
$var=1;
function proc_scrn($var1){
    echo "tp12: ".$var1;
}
proc_scrn($var);
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.