Category: PHP Arrays

PHP Arrays

Merging arrays in php

Merging arrays in php

array_merge Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array. Syntax Example Output

Count all the values of an array in php

Count all the values of an array in php

The array_count_values() function counts all the values of an array. It returns an associative array, where the keys are the original array’s values, and the values are the number of occurrences. Example Output

Arrays sorting in php

Arrays sorting in php

sort() function This function sorts an array. Elements will be arranged from lowest to highest when this function has completed. Output :

join() function php

join() function php

The join() function returns a string from the elements of an array.   The join() function is an alias of the implode() function. Output

PHP implode() Function

PHP implode() Function

The implode() function returns a string from the elements of an array. Syntax implode(separator,array) Example Output

explode function php

explode function php

The explode() function breaks a string into an array. Syntax is : explode(separator,string,limit); Example Output

Using Array Functions

Using Array Functions

1. is_array() Arrays and variables share the same namespace. This means that you cannot have a string variable called $fred and an array also called $fred. If you’re in doubt and your code needs...

Multidimensional Arrays

Multidimensional Arrays

A simple design feature in PHP’s array syntax makes it possible to create arrays of more than one dimension. In fact, they can be as many dimensions as you like (although it’s a rare...

For each loop with arrays

For each loop with arrays

The creators of PHP have gone to great lengths to make the language easy to use. So, not content with the loop structures already provided, they added another one especially for arrays: the foreach…as...

Associative Arrays

Associative Arrays

Keeping track of array elements by index works just fine, but can require extra work in terms of remembering which number refers to which product. It can also make code hard for other programmers...