PHP and JQuery Interview Questions & Answers

Posted On:June 26, 2019, Posted By: Latest Interview Questions, Views: 238, Rating :

Best PHP and JQuery Interview Questions and Answers

Dear Readers, Welcome to PHP and JQuery Interview Questions and Answers have been designed specially to get you acquainted with the nature of questions you may encounter during your Job interview for the subject of PHP and JQuery. These PHP and JQuery Questions are very important for campus placement test and job interviews. As per my experience good interviewers hardly plan to ask any particular questions during your Job interview and these model questions are asked in the online technical test and interview of many IT companies.

 

1. What is jQuery ?

It’s very simple but most valuable Question on jQuery means jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, animating, event handling, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. jQuery is build library for javascript no need to write your own functions or script jQuery all ready done for you
 
Interview Questions PHP and JQuery

2. Change the URL for a Hyperlink using jQuery

There are three way to change   the URL for a Hyperlink using jQuery.
1-   $("a").attr("href", "http://www.phpinterviewquestion.com/");
2- $("a[href='http://www.phpinterviewquestion.com/']")
    .attr('href',   'http://phpinterviewquestion.com/');
3-  $("a[href^='http://phpinterviewquestion.com']").each(function(){
      this.href = this.href.replace(/^http:\/\/beta\.phpinterviewquestion\.com/,
 "http://phpinterviewquestion.com");
     });
 

3. Check or Uncheck All Checkboxes using jquery

There  are different methods to check and uncheck the check boxes.
suppose that you have checkboxes like that
<input type=”checkbox”  value=”1? name=”Items”  id=”Items1? />
<input type=”checkbox”  value=”2? name=”Items”  id=”Items2? />
<input type=”checkbox”  value=”3? name=”Items”  id=”Items3? />
<input type=”checkbox”  value=”1? name=”Items”  id=”Items4? />
1- using attr() function.
$(‘#checkall’).click(function(){
$(“input[@name='Items']:checked”).attr(‘checked’,true);
});
$(‘#uncheckall’).click(function(){
$(“input[@name='Items']:checked”).attr(‘checked’,false);});
2- using attr() and removeAttr()funstions
$(‘#checkall’).click(function(){
$(“input[@name='Items']:checked”).attr(‘checked’,true);
})
$(‘#uncheckall’).click(function(){
$(“input[@name='Items']:checked”).removeAttr(‘checked’);})
 

4. fetch the values of selected checkbox array using JQuery

Suppose that below is checkbox array
<input type=”checkbox”  value=”1? name=”Items[]“  id=”Items1? />
<input type=”checkbox”  value=”2? name=”Items[]“  id=”Items2? />
<input type=”checkbox”  value=”3? name=”Items[]“  id=”Items3? />
<input type=”checkbox”  value=”1? name=”Items[]“  id=”Items4? />
and we want the get the value of selected checkbox using jquery.
then simple use below code.
var selItems = new Array();
$(input[@name='Items[]‘]:checked”).each(function() {selItems .push($(this).val());});
Here selItems will take all selected value of checkbox.
 

5. How we can apply css in multiple Selectors in jquery.

Here  to take effect is example to demonstrate
$(“div,span,p.myClass”).css(“border”,”1px solid green”);
the border will be apply in all div,span ,p.myClass class element.
 

6. How we can modify the css class in jquery.

Using css method we can modify class using jquery
example:$(“.CssClass1.CssClass2?).css(“border”,”1px solid green”);
CssClass1,CssClass2 will be modify to border  1px solid green.
 

7. How can we apply css in div using jquery

using css() method we can apply css in div element.
example:
$(“div”).css(“border”,”1px solid green”);
 

8. get the value of selected option in jquery

<select id="sel">
   <option   value  ="1">Hi</option>
   <option value="2">Hello</option>
   <option value="3">Helloooooo</option>
   <option value="4">ok</option>
   <option value="5">Okey</option>
 </select>
want to get  the  value of selected option, then use
   $("select#sel").val();
or text of selected box, then use
$("#seloption:selected").text();
 

9. check/uncheck an input in jquery?

Using two function, we can perform the operation.
// Check #x
$(“#checkboxid”).attr(“checked”, “checked”);
// Uncheck #x
$(“#checkboxid”).removeAttr(“checked”);
 
10. disable/enable an element in jquery?
// Disable #x
$(“#x”).attr(“disabled”,”disabled”);
// Enable #x
$(“#x”).removeAttr(“disabled”);
 

11. Why is jQuery better than JavaScript? 

* jQuery is great library for developing ajax based application.
* It helps the programmers to keep code simple and concise and reusable.
* jQuery library simplifies the process of traversal of HTML DOM tree.
* jQuery can also handle events, perform animation, and add the Ajax support in web applications.
 

12. When can you use jQuery? 

JQuery can be used to apply CSS, call functions on events, traverse the documents, manipulation purpose and to add effects too.
 

13. Advantages of jQuery. 

The advantages of using jQuery are:
* JavaScript enhancement without the overhead of learning new syntax
* Ability to keep the code simple, clear, readable and reusable
* Eradication of the requirement of writing repetitious and complex loops and DOM scripting library calls
 

14. Explain the features of jQuery? 

Features of jQuery are :
* Effects and animations
* Ajax
* Extensibility
* DOM element selections functions
* Events
* CSS manipulation
* Utilities – such as browser version and the each function.
* JavaScript Plugins
* DOM traversal and modification
 

15. How can we apply css in odd childs of parent node using JQuery library.

$(”tr:odd”).css(”background-color”, “#bbbbff”);
 

16. How can we apply css in even childs of parent node using JQuery library.

$(”tr:even”).css(”background-color”, “#bbbbff”);
 

17. How can we apply css in last child of parent using JQuery library.

$(”tr:last”).css({backgroundColor: ‘yellow’, fontWeight: ‘bolder’});
 

18. What distinguishes PHP from something like client side Java Script?

Java script applied on client side while in php code  executed on server reviews side.
 

19. In PHP how can you jump in to and out of “php mode”?

The Php code is enclosed in special Start < ? and end ? > tags that allow  ingredients you to jump in to and out of “php mode”.
 

20. What does a special set of tags do in PHP?

The tags <?= and ?>  displayed  output directly to the web  browser.
 

21. How can we Calculate the similarity between two strings

Using similar_text() get similarity between two strings.
Return Values
Returns the number of matching chars in both strings.
example
<?php
$first =’php3';
$first  =’php4';
echo  retail price similar_text ( $first, $second )  //3
?>
 

22. Return ASCII value of character in php?

using ord() method we can get ASCII value of character in php.
<?php
$str = "\n" style="color: #007700;">;
if (ord style="color: #0000bb;">$str) == 10) {
echo "The first character of \$str is a line feed.\n";
}
?>
 

23. How can I execute a PHP script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file  name as the command line argument. For example, “php  myScript.php”, assuming “php” is the command to invoke the CLI program. Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.
 

24. What difference between require() and require_once().

Require()
The  Require() is  used to include a file, It create fatal  error if file not found and  terminate  script.
require_once()
The require_once() to require() except PHP will check if the file has already been included, and  if so, tricor online not include (require) it again.
 

25. What does dollar Sign ($) means in JQuery?

Dollar Sign is nothing but it's an alias for JQuery. 
Take a look at below jQuery code 
$(document).ready(function()
{
}
);
Over here $ sign can be replaced with "jQuery " keyword. 
jQuery(document).ready(function(){
});
 

26. How is body onload() function is different from document.ready() function used in jQuery?

Document.ready() function is different from body onload() function because off 2 reasons. 
1. We can have more than one document.ready() function in a page where we can have only one onload function. 
2. Document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page. 
 

27. What is JQuery UI?

JQuery UI is a library which is built on top of JQuery library. JQuery UI comes with cool widgets, effects and interaction mechanism. 
 

28. Name some of the methods of JQuery used to provide effects?

Some of the common methods are : 
1. Show() 
2. Hide() 
3. Toggle() 
4. FadeIn() 
5. FadeOut() 
 

29. What are the different type of selectors in Jquery?

There are 3 types of selectors in Jquery 
1. CSS Selector 
2. XPath Selector 
3. Custom Selector 
 

30. How can you select all elements in a page using jQuery?

To select all elements in a page, we can use all selectors, for that we need to use *(asterisk symbol). 
<script language="javascript" type="text/javascript">
         $("*").css("border", "2px dotted red"); 
</script>
 

31. Which version of jQuery file should be used?

In most of the recent releases so far, the core functionality of jQuery remains same however some more cool and better features are added. Ideally you should use the latest jQuery files available on the jQuery.com website. By doing this you ensure that your earlier functionality will still work and you can use new features available as part of the new release.
 

32. What are Selectors in jQuery mean ?

Generally in HTML, if we need to work with any control on a web page we need to find the control. For that we use document.getElementByID or document.getElementByName. But in jquery we do it using Selectors. 
Using this selectors we can select all the controls as well using a symbol (* ) 
A sample code snippet can be of this form 
<script language="javascript" type="text/javascript">
$("*").css("border", "10px red");
</script>
 

33. Do we need to add the JQuery file both at the Master page and Content page as well?

No, if the Jquery file has been added to the master page then we can access the content page directly without adding any reference to it. 
This can be done using this simple example 
<script type="text/javascript" src="jQuery-1.4.1-min.js"></script>
 

34. What is the advantage of using the minified version of JQuery rather than using the conventional one?

The advantage of using a minified version of JQuery file is Efficiency of the web page increases. 
The normal version jQuery-x.x.x.js has a file size of 178KB 
but the minified version jQuery.x.x.x-min.js has 76.7 KB. 
The reduction in size makes the page to load more faster than you use a conventional jQuery file with 178KB.
 

35. What is CDN and how jQuery is related to it?

CDN - It stands for Content Distribution Network or Content Delivery Network. 
Generally, a group of systems at various places connected to transfer data files between them to increase its bandwidth while accessing data. The typical architecture is designed in such a way that a client access a file copy from its nearest client rather than accessing it from a centralized server. 
So we can load this jQuery file from that CDN so that the efficiency of all the clients working under that network will be increased. 
Example : 
We can load jQuery from Google libraries API 
<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
 

36. Can we select a element having a specific class in jQuery ?

Yes, we can select an element with a specific class, we use the class selector.The class name must contain the prefix as "." (dot). 
<script language="javascript" type="text/javascript">
         $(".class1").css("border", "2px solid red");
</script>
 

37. What are features of JQuery or what can be done using JQuery?

Features of Jquery 
1. One can easily provide effects and can do animations. 
2. Applying / Changing CSS. 
3. Cool plugins. 
4. Ajax support 
5. DOM selection events 
6. Event Handling 
 

38. What are the advantages of JQuery ?

There are many advantages with JQuery. Some of them are : 
. It is more like a JavaScript enhancement so there is no overhead in learning a new syntax. 
. It has the ability to keep the code simple, readable, clear and reusable. 
. It would eradicate the requirement for writing complex loops and DOM scripting library calls.