50 Php Objective Type Quiz & MCQs with Answers for Interview Preparation

Gyansetu Team Web Development/Programming
PHP CodeIgniter course in Gurgaon

Practice these MCQs to strengthen your PHP and CodeIgniter knowledge and prepare confidently for job interviews or certification exams.
Whether you’re aiming to become a backend specialist, a full-stack developer, or simply sharpen your skills in MVC architecture, REST APIs, database integration, and server-side scripting — you’re in the right place.
50+ PHP CodeIgniter MCQs covering everything from core PHP syntax, routing, controllers, models, views, helpers, sessions, validation, and security — complete with answers to help you test and solidify your understanding, no guesswork involved.

✅ Section 1: Core PHP Basics – 10 MCQs

  1. What is the correct way to start a PHP block?
    A. <?php ?>
    B. <php> </php>
    C. <? ?>
    D. <!php> </!php>
    Answer: A
  2. Which of the following is used to declare a variable in PHP?
    A. $var = 10;
    B. int var = 10;
    C. declare var = 10;
    D. var := 10;
    Answer: A
  3. What is the output of echo 5 + ‘5 days’; in PHP?
    A. 55
    B. 10
    C. Error
    D. 5 days
    Answer: B
  4. Which function is used to include one PHP file into another?
    A. insert()
    B. require()
    C. echo()
    D. printf()
    Answer: B
  5. Which of these is NOT a PHP superglobal?
    A. $_POST
    B. $_DATA
    C. $_GET
    D. $_SESSION
    Answer: B
  6. What does the isset() function check?
    A. If variable is empty
    B. If variable exists and is not NULL
    C. If variable is boolean
    D. If variable is numeric
    Answer: B
  7. How are arrays defined in PHP?
    A. arr = [1, 2, 3];
    B. $arr = array(1, 2, 3);
    C. int[] arr = {1, 2, 3};
    D. $arr = new array[1,2,3];
    Answer: B
  8. What is the default method for HTML forms?
    A. GET
    B. POST
    C. PUT
    D. DELETE
    Answer: A
  9. Which operator is used for string concatenation in PHP?
    A. +
    B. .
    C. &
    D. ::
    Answer: B
  10. What does die() do in PHP?
    A. Kills the browser
    B. Deletes a variable
    C. Terminates script execution
    D. Loops forever
    Answer: C
.NET MVC course

Master PHP with CodeIgniter – Build Dynamic Web Apps in Gurgaon


✅ Section 2: CodeIgniter Fundamentals – 10 MCQs

  1. CodeIgniter is based on which design pattern?
    A. Singleton
    B. Factory
    C. MVC
    D. Proxy
    Answer: C
  2. Which folder contains user-defined controllers in CodeIgniter?
    A. system/controllers/
    B. application/controllers/
    C. core/controllers/
    D. assets/controllers/
    Answer: B
  3. What is the default controller in CodeIgniter 3?
    A. index.php
    B. main.php
    C. Welcome.php
    D. home.php
    Answer: C
  4. How do you load a model in CodeIgniter?
    A. $this->model(‘modelname’);
    B. $this->load->model(‘modelname’);
    C. include ‘modelname.php’;
    D. $model = new Model();
    Answer: B
  5. What is the purpose of a model in MVC?
    A. Handle database operations
    B. Manage routing
    C. Generate HTML
    D. Process CSS
    Answer: A
  6. Where are view files stored in CodeIgniter?
    A. application/html/
    B. application/templates/
    C. application/views/
    D. system/views/
    Answer: C
  7. How do you pass data to a view in CodeIgniter?

$this->load->view(‘example’, $data);

A. True
B. False
Answer: A

  1. Which helper helps with form creation?
    A. form_helper
    B. html_helper
    C. url_helper
    D. input_helper
    Answer: A
  2. What does $this->input->post(’email’) do?
    A. Loads email library
    B. Fetches POST data from form
    C. Sends email
    D. Sets a session variable
    Answer: B
  3. How do you load a helper in CodeIgniter?
    A. helper(‘url’);
    B. load_helper(‘url’);
    C. $this->helper(‘url’);
    D. $this->load->helper(‘url’);
    Answer: D

✅ Section 3: Routing & URL Handling – 10 MCQs

  1. Which file defines URL routes in CodeIgniter?
    A. routes.php
    B. config.php
    C. web.php
    D. index.php
    Answer: A
  2. Which function redirects to another controller method?
    A. redirect()
    B. send()
    C. goto()
    D. call()
    Answer: A
  3. What is URI segment in CodeIgniter?
    A. Path in HTML
    B. Part of URL after base URL
    C. Session name
    D. Cookie identifier
    Answer: B
  4. Which CodeIgniter function retrieves URL segment?
    A. get_uri()
    B. $this->uri->segment()
    C. uri_part()
    D. url()->segment()
    Answer: B
  5. Which config item changes the base URL?
    A. routes.php
    B. index.php
    C. config.php
    D. constants.php
    Answer: C
  6. How to enable pretty URLs in CI (remove index.php)?
    A. Configure .htaccess
    B. Rename router
    C. Use query strings
    D. Edit views
    Answer: A
  7. Which function sets a custom route?

$route[‘products’] = ‘productController/index’;

A. True
B. False
Answer: A

.NET MVC course

From Beginner to Backend Pro – CodeIgniter Training in Gurgaon

  1. What does $config[‘base_url’] define?
    A. Default route
    B. Base system path
    C. Application root URL
    D. Admin panel URL
    Answer: C
  2. Which method loads a library in CodeIgniter?
    A. library_load(’email’);
    B. $this->load->library(’email’);
    C. use email;
    D. import email;
    Answer: B
  3. How to call controller method from browser URL?
    A. /controller-method
    B. /index.php/controller/method
    C. /site.controller.method
    D. /call/controller.method
    Answer: B

✅ Section 4: Database Integration – 10 MCQs

  1. Which function executes a SQL query in CodeIgniter?
    A. $this->query();
    B. $this->db->query();
    C. runQuery();
    D. $this->execute();
    Answer: B
  2. How do you enable the database in CodeIgniter?
    A. Create db.php
    B. Load DB library manually
    C. Edit application/config/database.php
    D. Create .sql file
    Answer: C
  3. What function returns query result as array of objects?
    A. result()
    B. fetch_all()
    C. object()
    D. query_result()
    Answer: A
  4. Which method inserts a record into the database?
    A. $this->db->add()
    B. $this->db->insert()
    C. $this->db->create()
    D. $this->insert_row()
    Answer: B
  5. How do you get the last inserted ID?
    A. $this->db->last_insert_id()
    B. $this->db->last_id()
    C. $this->db->insert_id()
    D. $this->insert->id()
    Answer: C
  6. Which method fetches a single row from result?
    A. row()
    B. one()
    C. fetch()
    D. first()
    Answer: A
  7. How do you write a where condition in CI?

$this->db->where(‘id’, 1);

A. True
B. False
Answer: A

  1. Which method updates records?
    A. $this->db->edit()
    B. $this->db->update()
    C. $this->db->change()
    D. $this->db->save()
    Answer: B
  2. What returns the total number of affected rows?
    A. $this->db->rows()
    B. $this->db->affected_rows()
    C. get_row_count()
    D. $this->affected()
    Answer: B
  3. Which CodeIgniter file defines DB connection credentials?
    A. config.php
    B. autoload.php
    C. database.php
    D. routes.php
    Answer: C
.NET MVC course

Learn PHP CodeIgniter in Gurgaon – Code Faster, Smarter, Better


✅ Section 5: Sessions, Validation & Security – 10 MCQs

  1. Which function sets session data in CI?
    A. set_session()
    B. $this->session->set_userdata()
    C. $this->set->session()
    D. session()->set()
    Answer: B
  2. How to retrieve session value named user_id?
    A. $this->session->user_id;
    B. $this->session->get(‘user_id’);
    C. $this->session->userdata(‘user_id’);
    D. $_SESSION[‘user_id’];
    Answer: C
  3. Which library is used for form validation?
    A. form_lib
    B. validate
    C. form_validation
    D. validator
    Answer: C
  4. What does xss_clean() do?
    A. Sanitizes HTML
    B. Prevents Cross-Site Scripting
    C. Checks sessions
    D. Encrypts URLs
    Answer: B
  5. Which helper helps in URL creation and manipulation?
    A. path_helper
    B. html_helper
    C. url_helper
    D. uri_helper
    Answer: C
  6. Which library encrypts session data?
    A. crypto_lib
    B. encrypt
    C. encryption
    D. secure_data
    Answer: C
  7. What function validates an email field in form validation?
    A. email_valid
    B. valid_email
    C. check_email
    D. is_email
    Answer: B
  8. Which file sets autoloaded libraries and helpers?
    A. database.php
    B. routes.php
    C. autoload.php
    D. config.php
    Answer: C
  9. What is CSRF in CodeIgniter?
    A. Cookie Security Rule Filter
    B. Cross-Site Request Forgery protection
    C. Client-Side Render Form
    D. Cross Server Routing Filter
    Answer: B
  10. How do you enable CSRF protection in CodeIgniter?
    A. .htaccess
    B. Modify autoload.php
    C. $config[‘csrf_protection’] = TRUE; in config.php
    D. $this->enable_csrf();
    Answer: C

Mastering these PHP CodeIgniter MCQs is a valuable step toward building a strong foundation in backend development, MVC architecture, RESTful APIs, and dynamic server-side scripting.
If you’re ready to elevate your career with hands-on projects and expert-led instruction, join our PHP CodeIgniter course in Gurgaon at Gyansetu and become industry-ready for high-demand backend and full-stack development roles.

.NET MVC course

Learn PHP CodeIgniter in Gurgaon – Code Faster, Smarter, Better

Gyansetu Team

Leave a Comment

Your email address will not be published. Required fields are marked *

Categories
Drop us a Query
+91-9999201478

Available 24x7 for your queries

Please enable JavaScript in your browser to complete this form.