কম্পিউটার

পিএইচপি তুলনা অবজেক্ট


পরিচয়

PHP এর একটি তুলনা অপারেটর আছে == যা ব্যবহার করে দুটি বস্তুর ভেরিয়েবলের একটি সহজ তুলনা করা যেতে পারে। উভয়ই একই শ্রেণীভুক্ত হলে এবং সংশ্লিষ্ট বৈশিষ্ট্যের মান একই হলে এটি সত্য হয়।

পিএইচপি এর === অপারেটর দুটি অবজেক্ট ভেরিয়েবলের তুলনা করে এবং সত্য প্রদান করে যদি এবং শুধুমাত্র যদি তারা একই ক্লাসের একই উদাহরণ উল্লেখ করে

এই অপারেটরের সাথে বস্তুর তুলনা করার জন্য আমরা নিম্নলিখিত দুটি ক্লাস ব্যবহার করি

উদাহরণ

<?php
class test1{
   private $x;
   private $y;
   function __construct($arg1, $arg2){
      $this->x=$arg1;
      $this->y=$arg2;
   }
}
class test2{
   private $x;
   private $y;
   function __construct($arg1, $arg2){
      $this->x=$arg1;
      $this->y=$arg2;
   }
}
?>

একই শ্রেণীর দুটি বস্তু

উদাহরণ

$a=new test1(10,20);
$b=new test1(10,20);
echo "two objects of same class\n";
echo "using == operator : ";
var_dump($a==$b);
echo "using === operator : ";
var_dump($a===$b);

আউটপুট

two objects of same class
using == operator : bool(true)
using === operator : bool(false)

একই বস্তুর দুটি উল্লেখ

উদাহরণ

$a=new test1(10,20);
$c=$a;
echo "two references of same object\n";
echo "using == operator : ";
var_dump($a==$c);
echo "using === operator : ";
var_dump($a===$c);

আউটপুট

two references of same object
using == operator : bool(true)
using === operator : bool(true)

বিভিন্ন শ্রেণীর দুটি বস্তু

উদাহরণ

$a=new test1(10,20);
$d=new test2(10,20);
echo "two objects of different classes\n";
echo "using == operator : ";
var_dump($a==$d);
echo "using === operator : ";
var_dump($a===$d);

আউটপুট

আউটপুট নিম্নলিখিত ফলাফল দেখায়

two objects of different classes
using == operator : bool(false)
using === operator : bool(false)

  1. মধ্যে পার্থক্য!==এবং ==! পিএইচপি-তে অপারেটর

  2. পিএইচপি ব্যবহার করে র্যান্ডম স্ট্রিং তৈরি করা

  3. পিএইচপিতে ডাবল না (!!) অপারেটর

  4. পিএইচপিতে দুটি তারিখের তুলনা করা হচ্ছে