Posts

Showing posts from September, 2018

Find pair of n numbers in php

Image
Recently I was working on mobile project in which we were working on service code in php, To find the pair in certain number in list.  Example:  $total = 4; $pair_total = $total * ($total - 1) * 0.5; // 6 So here we are able to find the pair combination using this formula.And pls comment if there any tricks similar to this.

Question: Why should we use class name in another class constructor function in php7?

I was working around oops in php 7 ,in which I pass class name and variable to another class constructor function to access the function of it Like inheritance concept.Let me brief with example Example for passing class name and variable in constructor  : class A{    public function execute($user){    echo $user;   } } class B {   protected $a; //where we pass Class A  inside constructor   public function __construct(A $a){      $this->a = $a;   }  public function show(){     $user = 'pramodh';     $this->a->execute($user);    } } $b = new B(new A); $b->show(); Out Put : Pramodh Example for passing just variable  in constructor  : class A{    public function execute($user){    echo $user;   } } class B {   protected $a; //where we pass Class A  inside constructor   public function __construct($a){      $this->a = $a;   }  public function show(){     $user = 'pramodh';