PHP Interview Questions In Hindi : PHP Interview Preparation

Blogs ❯❯ PHP

Image could not load

Image on pixabay

Hello learners , इस article में ऐसे कुछ important questions answers के साथ बात करेंगे जो interview के point of view से काफी सही हैं और पूछे जाने के chances भी ज्यादा हैं।

What is the purpose of using PHP?

Answer : Actually server side से related किसी भी काम को PHP से easily handle किया जा सकता है , जैसे forms से data receive करना , generate dynamic page content, different - different databases के साथ work करना , sessions को manage करना , cookies को send और receive , emails send आदि जैसे कई काम कर सकते हैं।

इसके अलावा PHP use करने के कई advantages हैं जैसे-

  1. Platform Independent

  2. Open source and Library support

  3. Diff - Diff Database Connectivity

  4. Easy to understand and code

  5. Easy integration and consistency

  6. Performance

  7. Reliability

What is the difference between echo and print in PHP?

सबसे बड़ा difference यह है कि echo() function किसी value को print करने के बाद कुछ return नहीं करता जबकि print() function value को print करने के बाद 1 return करता है।

Read more about it ...

How can you define constant variable in PHP ?

PHP में हम दो तरह से constant variables को define करते हैं।

  1. without OOPs PHP में constant variables को define करने के लिए हम define() function का use किया जाता हैं।

  2. जबकि Class में define करने के लिए हम const keyword का use करते हैं।

What is OOP in PHP ?

OOP Object Oriented Programing का ही sort form है। Java , C++ की तरह ही PHP भी OOP Concept को support करती है। OOP concept PHP Version 5 में add किया गया था , उससे पहले PHP में OOP का कोई concept नहीं था।

OOP (Object Oriented Programing) Classes और Objects पर based एक Programming Paradigm / Approach है। Simple भाषा में कहें तो OOP (Object Oriented Programing) Real World Entity/Object को Programming में represent करने का method / way है।

Real World Entity को ही Programing में Class / Object द्वारा represent किया जाता है। Entity की कुछ Properties या Behavior होता है जिसे Programing में Class variables & methods से represent किया जाता है।

Read more about OOP ...

Why do we use isset() ?

isset() function check करता है कि कोई variable declare किया गया है और null नहीं है। variable declare और null न होने पर true return करता है otherwise false.

हालाँकि आप कई variables को एक साथ check करते हैं तो , सभी variables set होने पर true return होता है , एक भी variable set नहीं हुआ तो false return होगा। इन variables का evaluation left से right की तरफ होता है , जैसे ही कोई unset variable आता है वही से evaluation stop हो जाता है।

Read more about isset() ...

What is type casting ?

किसी दी गयी value / variable को दूसरे type के variable में convert करना Type Casting या Type Conversion कहते हैं। different
type की values को different type में type cast करने के लिए उनके respective में convert करने के लिए value के आगे data type का name लिखा जाता है।

Example :

(int)$var; # type cast in to Int. (float)$var; # type cast in to Float. (string)$var; # type cast in to String. (bool)$var; # type cast in to Boolean.

Is false & FALse same ?

Yes, PHP में defined सभी keywords और functions case insensitive हैं। even user defined functions भी case insensitive हैं। हालाँकि यह pure case insensitive नहीं है।

Variable length argument function in PHP

Answer : Actually normal functions को जब हम define करते थे तो हमें
need के according parameters भी define करते थे , और उस function को Call करते समय हमें उसी के accordingly values / arguments भी pass किये जाते थे।

अब अगर हमें ये नहीं मालूम हो कि function call करते समय कितने arguments pass हो रहे हैं , इस तरह के functions को handle करने के लिए हमें PHP ने facility provide की है Variable Length Arguments की , जिसकी help से हम pass किये गए सभी arguments / values को easily handle कर सकते हैं।

इसके लिए हमें function define करते समय variable से पहले सिर्फ triple dots (...) prepend करने होते हैं।

Syntax :

function function_name(...$var)
{
  // यहां $var एक array variable जिसमे function call करते समय आपके द्वारा pass किये सभी arguments available है। 
}

Arrow Functions In PHP

Answer :
PHP में Arrow Functions PHP version 7.4 में introduce किये गए थे। जब हमें short expression calculate / evaluate करना हो तो complete function define करने के जगह Arrow Function use कर सकते हैं।

Arrow
Functions में curly braces और return keyword की जरूरत नहीं पड़ती है। Arrow Function में direct parenthesis के बाद expression लिखते हैं , और expression evaluate होकर automatically return हो जाता है।

Example :

<?php $y = 1; $myfun = fn($x) => $x * 10; echo $myfun(10); ?>

Output :

In how many ways can we define String in PHP ?

String series of characters या group of characters होती है , PHP में मुख्यता चार तरह से हम string define करते हैं -

  1. Single Quoted

  2. Double Quoted .

  3. heredoc syntax .

  4. newdoc syntax .

Difference between Single & Double Quoted String

PHP में Single और Double Quoted String में सबसे बड़ा difference यह है कि Single quoted string में हम कोई variable parse नहीं करा सकते हैं , मीन्स कोई variable को print नहीं करा सकते हैं।

जबकि Double Quoted String में easily किसी variable को print करा सकते हैं।

Read More about String ...

Types of Array in PHP

PHP में Array एक ordered map है।  और map एक type है
जो value को key के साथ associate करता है means key value pair में data store करता है।

PHP में दो type के array होते हैं।

  1. Indexed Array : PHP में indexed array , store की गयी values को index number के रूप में associate करता है जो कि 0 start होता है।

  2. Associated Array : Associative Array , values को key के साथ associate करता है , means Associative Array में हम values के साथ-साथ key  भी define करते हैं। Array values को key के साथ associate करने  के लिए हम => का use करते हैं।

और दोनों में ही हम comma ( , ) separated values pass करते हैं।

Read more about Array ...

Write down some important Array functions

PHP हमें कई सारे array functions provide कराती है जिनकी help से हम Array create , update , array merge और बहुत से Operations perform कर सकते हैं। कुछ array functions इस प्रकार हैं -

  1. count() : यह Array में मौजूद element की संख्या बताता है।

  2. is_array() : is_array() method check करता है , कि कोई variable Array है या नहीं।

  3. array_push() : array_push() method का use एक या एक से अधिक values को Array में append (Add) करने के लिए किया जाता है।

  4. array_pop() : array_pop() function , Array में से last element remove है।

  5. array_shift() : array_shift() function , Array में से first element remove करता है।

  6. array_unshift() : array_unshift() method का use एक या एक से अधिक values को Array में prepend (Add) करने के लिए किया जाता है।

  7. in_array() : in_array() check करता है कि value Array में exist करती है या नहीं।

  8. array_search() : array_search() का use किसी Array में value को search करने के लिए किया जाता है।

  9. array_map() : array_map() function Array के प्रत्येक value को user defined callback function में send करता है , और एक Array नई values के साथ return करता है।

  10. explode() : explode() function का use String से Array में convert करने के लिए किया जाता है।

  11. array_merge() : array_merge() , एक या एक से अधिक Array के elements को आपस में merge करता है।

Difference between isset() & empty()

empty() और isset() function में main different ये है कि isset() function ये check करता था कि कि कोई variable declare किया गया है या नहीं और उस variable की value null न हो , वही दूसरी तरफ empty() यह check करता है की define किया गया variable empty तो नहीं है।

यहां empty का मतलब है variable की value null , empty string , false और 0 नहीं होनी चाहिए।

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook