Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Chandu yadav
Page 28 of 81
define() function in PHP
The define() function defines a constant in PHP. Constants are global variables whose values cannot be changed during script execution. Syntax define(const_name, value, case_insensitive) Parameters const_name − The name of the constant (string). value − The value of the constant (scalar value). case_insensitive − Optional. Whether the constant name should be case-insensitive (default: false). Return Value The define() function returns true on success or false on failure. Examples Basic Example The following example defines a constant and accesses it directly ? ...
Read MoreFILTER_SANITIZE_ENCODED constant in PHP
The FILTER_SANITIZE_ENCODED constant in PHP is used with the filter_var() function to URL-encode special characters in a string. This is particularly useful for sanitizing URLs and ensuring they contain only valid characters. Syntax filter_var($value, FILTER_SANITIZE_ENCODED, $flags) Flags and Options FILTER_FLAG_STRIP_LOW − Remove characters with ASCII value less than 32 FILTER_FLAG_STRIP_HIGH − Remove characters with ASCII value greater than 127 FILTER_FLAG_ENCODE_LOW − Encode characters with ASCII value less than 32 FILTER_FLAG_ENCODE_HIGH − Encode characters with ASCII value greater ...
Read MoreFILTER_VALIDATE_IP constant in PHP
The FILTER_VALIDATE_IP constant validates an IP address using PHP's filter_var() function. It checks if a given string is a valid IPv4 or IPv6 address format. Syntax filter_var($value, FILTER_VALIDATE_IP, $flags) Parameters $value − The IP address string to validate FILTER_VALIDATE_IP − The validation filter constant $flags − Optional flags to specify validation criteria Flags FILTER_FLAG_IPV4 − The value must be a valid IPv4 address FILTER_FLAG_IPV6 − The value must be a valid IPv6 address FILTER_FLAG_NO_PRIV_RANGE − The value must not be within a private range FILTER_FLAG_NO_RES_RANGE − The value must ...
Read MoreFILTER_VALIDATE_BOOLEAN constant in PHP
The FILTER_VALIDATE_BOOLEAN constant validates a value as a boolean option. It's useful when you need to convert string representations of boolean values into actual PHP boolean types. Return Value The FILTER_VALIDATE_BOOLEAN constant returns: TRUE for "1", "true", "on" and "yes" FALSE for "0", "false", "off" and "no" NULL for any other value Syntax filter_var($value, FILTER_VALIDATE_BOOLEAN, $flags) Example 1: Valid TRUE Values This example shows values that return TRUE − bool(true) bool(true) bool(true) Example 2: Valid FALSE Values This example demonstrates ...
Read Morefilter_list() function in PHP
The filter_list() function in PHP returns an array of all available filter names that can be used with PHP's filter functions like filter_var() and filter_input(). Syntax filter_list() Parameters This function does not accept any parameters. Return Value The function returns an indexed array containing the names of all available filters. If no filters are available, it returns an empty array. Example Here's how to use filter_list() to display all available filters − Practical Example with Filter IDs You can combine filter_list() with filter_id() to ...
Read MoreFind documents that contains specific field in MongoDB?
To find documents that contain a specific field in MongoDB, use the $exists operator. This operator checks whether a field exists in a document, regardless of its value. Syntax db.collection.find({ "fieldName": { $exists: true } }); Sample Data Let us create a collection with sample documents − db.findDocumentContainsSpecificFieldDemo.insertMany([ { "ProductPrices": { "Product1": 10, ...
Read MoreIs it possible to return a list of specific values from a MongoDB query?
Yes, you can return a list of specific values from a MongoDB query using the map() method or projection. The map() method transforms query results into an array of specific field values. Syntax db.collection.find().map(function(document){ return document.fieldName; }); Sample Data db.listOfSpecificValuesDemo.insertMany([ {"StudentName": "John"}, {"StudentName": "Chris"}, {"StudentName": "Robert"}, {"StudentName": "David"} ]); { "acknowledged": true, "insertedIds": { ...
Read MoreMongoDB query to get last inserted document?
To get the last inserted document in MongoDB, use sort() with _id in descending order along with limit(1). Since ObjectId contains a timestamp, sorting by _id in descending order retrieves the most recently inserted document. Syntax db.collection.find().sort({_id: -1}).limit(1); Sample Data Let us first create a collection with documents ? db.getLastInsertedDocument.insertMany([ {"Name": "John"}, {"Name": "Chris"}, {"Name": "Robert"} ]); { "acknowledged": true, "insertedIds": [ ...
Read MoreWrite an equality in MongoDB without using $eq operator
In MongoDB, you can write equality queries without using the $eq operator by using the implicit equality syntax. This involves directly specifying the field name and value in the query document. Syntax db.collection.find({"fieldName": "value"}); Sample Data Let us first create a collection with documents ? db.operatorDemo.insertMany([ {"StudentSubject": ["MongoDB", "MySQL", "Java"]}, {"StudentSubject": ["Java", "C", "C++"]} ]); { "acknowledged": true, "insertedIds": [ ObjectId("5cef94eaef71edecf6a1f6a2"), ...
Read MoreFinding highest value from sub-arrays in MongoDB documents?
To find the highest value from sub-arrays in MongoDB documents, use the aggregation framework with $unwind, $sort, and $limit operators to flatten arrays, sort by the target field, and return the top result. Syntax db.collection.aggregate([ { $unwind: "$arrayField" }, { $sort: { "arrayField.valueField": -1 } }, { $limit: 1 } ]); Sample Data db.findHighestValueDemo.insertMany([ { _id: 10001, "StudentDetails": [ ...
Read More