Find object by value in array of objects

In PHP we either create objects and their array, or database returns array of objects as result-set of some query. There we might need to find an object which have a particular property-value pair. There is no direct function available in PHP to perform the same so I’m explaining here how can we find object by value in array of objects by using a foreach loop.

Read More

Getting all element values using jQuery

Many times we face the problem of getting all the form controls or elements values of a long form. Because sometime getting so many controls by their id or name is very typical that make a long list.
So we need to opt a short way for getting all element values using jQuery. I have described three ways in this article.

Read More

Getting Checkbox Values in jQuery

Many times we use checkbox in the form control and post the form using jquery ajax and then we are required to access those form data from client side scripts, like Javascript. Among all possible form control, dropdown box, checkbox and radio buttons are having multiple options to select. So, we need to push all selected values of these form controls into an array using Javascript

Read More

Delete element by value from array (not by key)

While working with array in PHP sometimes we need to check if a value exists in an array and delete that key and value together from array. This simple code snippet below with explanation will help you to understand how can you delete element by value from array (not by key).

Read More

Only variables should be passed by reference

Sometime we face a unique type of problem during development and we watch the code thoroughly but not find the error where we are getting. ‘Only variables should be passed by reference‘ in $file_extension = end(explode(‘.’, $file_name)) is the same type of problem which does not seem as error in our code and it happens in usual code.

Read More

4 ways to empty an array in JavaScript

JavaScript arrays are commonly used by developers and making them empty is also used in practice. Here I am describing 4 ways to empty an array in JavaScript:

1. Use splice() method
2. Set length to zero
3. Using pop() method
4. Set array to new empty array

Read More

Array in JavaScript – push() Method

Array in JavaScript push() method appends the given element or elements in the last of array. It returns the length of the new array.

Syntax is as below:

array.push(item1, item2,.....itemN);

Read More

[ Page 1 of 2 ]