Answers for "php create class"

PHP
7

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
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
0

class php

test234234234234
Posted by: Guest on September-22-2021
-1

how to make php oop class

public className{
	public function __construct(){
    //CODE HERE
    }
}
Posted by: Guest on March-12-2020

Browse Popular Code Answers by Language