Server Side Programming Articles

Page 978 of 2109

Sort Array of Objects by Object Fields in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 4K+ Views

In PHP, you can sort an array of objects by their properties using several built-in functions. Each approach offers different advantages depending on your specific requirements and coding style preferences. Using usort() Function with a Custom Comparison Function The usort() function provides the most flexible approach for sorting objects by custom logic ? Bob - 25 Alice - 30 Charlie - 35 Using Anonymous Functions You can also use anonymous functions for more concise code ? Mouse - $25.5 Keyboard - $75 Laptop ...

Read More

Difference between fork() and exec() in C

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 4K+ Views

In C, fork() and exec() are fundamental system calls for process management. The fork() function creates a new process by duplicating the calling process, while exec() replaces the current process image with a new program. Syntax #include pid_t fork(void); int exec(const char *path, char *const argv[]); Key Differences Aspect fork() exec() Purpose Creates new process (duplicate) Replaces current process image Process Count Increases by one Remains same Memory Image Copies parent's memory Loads new program Return Value Child PID to parent, 0 to ...

Read More

Sort a Multidimensional Array by Date Element in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 6K+ Views

In PHP, you can sort a multidimensional array by a specific element, such as a date, using various approaches. Let's explore three different methods ? Using array_multisort() The array_multisort() function sorts multiple arrays or multidimensional arrays based on one or more columns ? Array ( [0] => Array ( [date] => 2023-05-15 [name] => Alice ...

Read More

pthread_self() in C

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 9K+ Views

The pthread_self() function in C is used to obtain the ID of the currently executing thread. This function provides a unique identifier for each running thread, allowing programs to distinguish between different threads during execution. Syntax pthread_t pthread_self(void); Parameters None − The function takes no parameters. Return Value Returns a pthread_t value representing the thread ID of the calling thread. Thread IDs are unique among all currently existing threads, but can be reused after a thread terminates. Example The following example demonstrates how pthread_self() works by ...

Read More

Saving an Image from URL in PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 11K+ Views

There are several ways to save an image from a URL in PHP. Here are three common methods − Using file_get_contents() and file_put_contents() Using cURL Using the GD library Using file_get_contents() and file_put_contents() Using file_get_contents() and file_put_contents() is a straightforward method to save an image from a URL in PHP ? In this code snippet, file_get_contents() retrieves the contents of the image file from the specified URL. The image data is then stored in the $image variable. Next, file_put_contents() saves ...

Read More

pthread_equal() in C

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 369 Views

The pthread_equal() function is used to check whether two threads are equal or not. This function returns 0 if the threads are different, or a non-zero value if the threads are equal. Syntax int pthread_equal(pthread_t th1, pthread_t th2); Parameters th1 − First thread identifier th2 − Second thread identifier Return Value Returns a non-zero value if threads are equal, otherwise returns 0. Note: To compile and run pthread programs, use: gcc -pthread filename.c -o output Example 1: Comparing Thread with Itself In this example, we ...

Read More

Refresh a Page Using PHP

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 5K+ Views

In PHP, you can refresh a page using the header() function to send HTTP headers to the browser. This is useful for creating auto-refreshing pages or redirecting users after form submissions. Using header() Function The header() function sends HTTP headers to the browser. To refresh a page, you use the "Refresh" header with a specified delay time. Syntax header(string $header, bool $replace = true, int $http_response_code = 0): void Parameters $header − The header string to send (e.g., "Refresh: 5") $replace − Whether to replace previous similar headers (default: true) $http_response_code ...

Read More

pthread_cancel() in C

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 781 Views

The pthread_cancel() function is used to send a cancellation request to a specific thread identified by its thread ID. This function allows one thread to request the termination of another thread in a controlled manner. Note: To compile and run pthread programs, use: gcc -pthread filename.c -o output Syntax int pthread_cancel(pthread_t thread); Parameters thread − The thread ID of the thread to be cancelled Return Value Returns 0 on success Returns an error number on failure Example: Thread Cancellation This example demonstrates how ...

Read More

PHP Program to Find the Number Occurring Odd Number of Times

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 309 Views

Finding a number that occurs an odd number of times in an array is a common programming problem. In PHP, this can be solved using different approaches like counting, hashing, or bitwise XOR operations. Problem Explanation Given an array where all numbers appear an even number of times except one, we need to find that single number which appears an odd number of times. For example, in the array [2, 3, 4, 3, 1, 4, 2, 1, 1], the number 1 appears 3 times (odd), while all other numbers appear an even number of times. Method ...

Read More

nextafter() and nexttoward() in C/C++

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 335 Views

The nextafter() and nexttoward() functions in C are used to find the next representable floating-point value after a given number in a specified direction. These functions are part of the math.h library and are useful for precise floating-point arithmetic operations. Syntax double nextafter(double x, double y); float nextafterf(float x, float y); long double nextafterl(long double x, long double y); double nexttoward(double x, long double y); float nexttowardf(float x, long double y); long double nexttowardl(long double x, long double y); Parameters x − The starting value y − The direction value. The function ...

Read More
Showing 9771–9780 of 21,090 articles
« Prev 1 976 977 978 979 980 2109 Next »
Advertisements