1. What does the json_decode function do in PHP?
The json_decode function converts a JSON string into a PHP array or object, making it easy to handle data from APIs or web services.
$arr = json_decode($json, true);
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
PHP · Question Set
PHP & Web Concepts interview questions for placements and exams.
Questions
15
Included in this set
Subject
PHP
Explore more sets
Difficulty
Mixed
Level of this set
Go through each question and its explanation. Use this set as a focused practice pack for PHP.
The json_decode function converts a JSON string into a PHP array or object, making it easy to handle data from APIs or web services.
$arr = json_decode($json, true);
For complete preparation, combine this set with full subject-wise practice for PHP. You can also explore other subjects and sets from the links below.
cURL supports multiple protocols, handles headers and cookies, and allows sending data in different formats like JSON or form-data. It is flexible for interacting with REST APIs or external web services securely.
REST is an architectural style for designing APIs that use standard HTTP methods like GET, POST, PUT, and DELETE for communication between client and server.
The json_encode function converts PHP data structures like arrays or objects into JSON strings, which can be sent over APIs or stored easily.
json_encode($data);
The PUT method is used to update or replace an existing resource on the server. It is idempotent, meaning multiple identical requests produce the same result.
A 404 status code indicates that the server cannot find the requested resource. It’s one of the most common response codes on the web.
cURL is a PHP library used to send and receive HTTP requests. It helps in communicating with APIs, external services, and web servers programmatically.
$ch = curl_init('https://api.example.com');The header function sends raw HTTP headers to the browser before any output. It’s commonly used for redirection and setting content type.
header('Location: login.php');The Content-Type header tells the browser how to interpret the response data, such as text/html or application/json.
header('Content-Type: application/json');A REST API response usually includes a status code, headers, and a body. The body often contains data in JSON format along with success or error messages. Headers describe content type and caching rules.
A PHP script reads the HTTP method (GET, POST, etc.), processes input data, performs logic like database operations, and returns a response with proper headers and status codes to the client.
JSON is lightweight, easier to read, and integrates naturally with JavaScript. It requires less bandwidth and simpler parsing compared to XML, making it ideal for fast web communication.
REST is based on stateless communication, resource-based URLs, standard HTTP methods, representation through JSON or XML, and the use of standard status codes for responses.
Headers like X-Frame-Options, Content-Security-Policy, and X-Content-Type-Options protect against attacks such as clickjacking, cross-site scripting, and MIME sniffing. Setting them correctly hardens PHP web apps against common exploits.
Token-based authentication verifies users using a unique token generated after login. The token is sent with each API request, and the server validates it before allowing access, eliminating the need to store credentials in every request.