0

I have the following codes:

<?php

// a)

function fnTripple($a)
{

$a = $a * $a;

return 3;
}

echo fnTripple(4);

// b)

$a = 5;
$b = 5;

// c)

$b = $b + $a;

// d)

$d = $d + $b;	
$e = $e + $b;

// e)

$f = function ($d)


// f)
$g = function ($d)
		{
		$e++;
		}

// g)

 echo $a
 echo $b
 echo $c
 echo $d
 echo $e 
 echo $f
 echo $g



?>

This errors appears:

Parse error: syntax error, unexpected T_VARIABLE, expecting '{' in C:\xampp\htdocs\php_exercise\exercise5.php on line 36

Line 36 is $g = function ($d)

What might be the problems?

Thanks.

5
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by karthik_ppts
0

Read up on creating functions in the php manual. Either you've missed the point or you didn't understand the syntax.

0

what is below code ?

$f = function ($d)


// f)
$g = function ($d)
		{
		$e++;
		}

What you want to do with this lines?

Edited by vibhaJ: n/a

0

I think your nedd is this

<?php
     
    // a)
     
    function fnTripple($a)
    {
     
    $a = $a * $a;
     
    return 3;
    }
     
    echo fnTripple(4);
     
    // b)
     
    $a = 5;
    $b = 5;
     
    // c)
     
    $b = $b + $a;
     
    // d)
    // $d=0;
    $d = $d + $b;
    $e = $e + $b;
     
    // e)
     
    $f = fnTripple($d);
     
     
    // f)
    $g = fnTripple($d);
    {
    $e++;
    }
     
    // g)
     
    echo $a."<br>";
    echo $b."<br>";
    echo $d."<br>";
    echo $e."<br>";
    echo $f."<br>";
    echo $g;
     
     
     
    ?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.