Answers for "create a class in php"

PHP
6

create a class in php

<?php
class Fruit {
  public $name;
  public $color;

  function __construct($name, $color) {
    $this->name = $name;
    $this->color = $color;
  }
  function get_name() {
    return $this->name;
  }
  function get_color() {
    return $this->color;
  }
}

$apple = new Fruit("Apple", "red");
echo $apple->get_name();
echo "<br>";
echo $apple->get_color();
?>
Posted by: Guest on July-22-2020
7

php define class

class Bike {
    	function Bike() {
            $this->type = 'BMX';
    }
}

$blackSheep = new Bike();

print $blackSheep->type;
Posted by: Guest on March-11-2020
5

class php

<?php
class Foo {
    public $aMemberVar = 'aMemberVar Member Variable';
    public $aFuncName = 'aMemberFunc';
   
   
    function aMemberFunc() {
        print 'Inside `aMemberFunc()`';
    }
}

$foo = new Foo;

function getVarName()
{
     return 'aFuncName'; 
}

print $foo->{$foo->{getVarName()}}();
Posted by: Guest on April-23-2020
1

php class

var array = [1, 2, 3, 4, 5, 6],
    s = 0,
    p = 1,
    i;
for (i = 0; i < array.length; i += 1) 
   {
    s += array[i];
    p *= array[i];
    }
console.log('Sum : '+s + ' Product :  ' +p);
Posted by: Guest on April-23-2021
3

oops concepts in php

The  PHP Object-Oriented Programming concepts are:
Class 
Objects
Inheritance
Interface
Abstraction
Magic Methods
Posted by: Guest on June-20-2020
-2

php class

var numbers = [10, 20, 30, 40] // sums to 100var sum = 0;for (var i = 0; i < numbers.length; i++) {  sum += numbers[i]}
Posted by: Guest on April-23-2021

Browse Popular Code Answers by Language