8 Tricky PHP Questions and Answers for Beginners

Hello guys, this time let us talk about few common PHP questions people face, specially beginners. These answers do not represent Respocert, and are marked by best one from the community members such as on stackoverflow.

Question No. 1

A user has enabled Htaccess and using this code

He want to make URLs of his website clean and he would like


Please use this code and you have to tweak it for use.

You can use second rule without any change in dynamics setting files (.htaccess style files) and http servers hosting settings. Rewriting module should be enabled.

Question No. 2

A user wants to add middleware inside a rout group in laravel and using this code

Now these routes are only available to logged in users and the users have owner privileges. He has started the session and stored privilege value by using this code.

But this code has not worked.


Please create custom middleware called owner.

This code will create middleware and then you have to do like this in public function called handle.

Then your custom middleware will look like this at the end.

Question No. 3

A user wants to send the data from a form to database by using this code.

When he gowa with the typical approach to submit the form, it causes the browsers to redirect. He wants to capture all the data and submit the data to PHP script by using jQuery and Ajax.


You can use this code in HTML

For JavaScript you can use this code

After the DOM is ready, above script should be done and insert $(document).ready() handler or you can also use $() shorthand.

Use this code in PHP (form.php)

To prevent injections and malicious you should sanitize posted data.

In JavaScript code, please use shorthand .post by replacing .aja.

Question No 4:

A user wants to check the element visibility and scroll down to it if available. He used this code but failed.


Please this use this code.

:visible makes easy for you.. You cannot test display==’block’,again and you must test for inline-block and check visibility setting.

Question No. 5

A user has multilingual website wants to use Yii or framework to prevent the slowness of website speed if lot of users comes to his domain. He has following config.php code.


Please use this code

After this part of your code

After that create dir where you have to language files. Then create the file needed in dir for all language files and copy related part of the code that took off from config.php.


Then another lang file

Question No. 6

A user ia using WooCommerce and he wants to show product attribute values on product category rather than names like this.

Plus if these values are not available than this line should not display anything. He want to use this code to achieve his goal.


Please use this code in function.php of your active theme.

There is one more alternative way, you can use this code in content-product.php

Question No. 7

A user is using this code to display product list.

He want 4 TD in one row, the last one will be an empty if there are three products.


The inner loop will execute once time anyway. You can try this code.

Question No 8

A user applied this code to create image gallery but getting different result.



Your code is not peculiar, you need some minor alternations. Use this code for desired result.


About me

To update Biographical Info , go to: http://yourwebsite/wp-admin/profile.php