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.

Check what you mean from line 31 to 35!

Member Avatar for diafol

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

what is below code ?

$f = function ($d)


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

What you want to do with this lines?

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;
     
     
     
    ?>
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.