answersLogoWhite

0

To create a PHP class it is pretty simple, I will show you how to create a very basic class in an example below.

<?php

// the class

class myBasicClass {

// a function to add 2 numbers together and return the result

function add($num1, $num2) {

$result = $num1 + $num2;

return $result;

}

}

// load up the class

$myBasicClass = new myBasicClass;

// output the result

echo $myBasicClass->add(5, 10); // outputs the result 15

?>

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach

Add your answer:

Earn +20 pts
Q: How do you create a PHP class?
Write your answer...
Submit
Still have questions?
magnify glass
imp