1 2 >   Sort: Rank

How To Get the Minimum or Maximum Value of an Array
How To Get the Minimum or Maximum Value of an Array? - PHP Script Tips - PHP Built-in Functions for Arrays If you want to get the minimum or maximum value of an array, you can use the min() or max() function. Here is a PHP script on how to use min() and max(): <?php $array = array(5, 7, 6, 2,...
2007-04-22, 6558👍, 0💬

How To Split a String into an Array of Substring
How To Split a String into an Array of Substring? - PHP Script Tips - PHP Built-in Functions for Arrays There are two functions you can use to split a string into an Array of Substring: explode(substring, string) - Splitting a string based on a substring. Faster than split(). split(pattern, string) ...
2007-04-22, 4803👍, 0💬

How To Join Multiple Strings Stored in an Array into a Single String
How To Join Multiple Strings Stored in an Array into a Single String? - PHP Script Tips - PHP Built-in Functions for Arrays If you multiple strings stored in an array, you can join them together into a single string with a given delimiter by using the implode() function. Here is a PHP script on how ...
2007-04-21, 4818👍, 0💬

How To Truncate an Array
How To Truncate an Array? - PHP Script Tips - PHP Built-in Functions for Arrays If you want to remove a chunk of values from an array, you can use the array_splice($array, $offset, $length) function. $offset defines the starting position of the chunk to be removed. If $offset is positive, it is coun...
2007-04-21, 6419👍, 0💬

How To Pad an Array with the Same Value Multiple Times
How To Pad an Array with the Same Value Multiple Times? - PHP Script Tips - PHP Built-in Functions for Arrays If you want to add the same value multiple times to the end or beginning of an array, you can use the array_pad($array, $new_size, $value) function. If the second argument, $new_size, is pos...
2007-04-21, 4730👍, 0💬

How To Create an Array with a Sequence of Integers or Characters
How To Create an Array with a Sequence of Integers or Characters? - PHP Script Tips - PHP Built-in Functions for Arrays The quickest way to create an array with a sequence of integers or characters is to use the range() function. It returns an array with values starting with the first integer or cha...
2007-04-21, 4781👍, 0💬

How To Randomly Retrieve a Value from an Array
How To Randomly Retrieve a Value from an Array? - PHP Script Tips - PHP Built-in Functions for Arrays If you have a list of favorite greeting messages, and want to randomly select one of them to be used in an email, you can use the array_rand() function. Here is a PHP example script: <?php $a...
2007-04-21, 5010👍, 0💬

How To Use an Array as a Stack
How To Use an Array as a Stack? - PHP Script Tips - PHP Built-in Functions for Arrays A stack is a simple data structure that manages data elements following the first-in-last-out rule. You use the following two functions together to use an array as a stack: array_push($array, $value) - Pushes a new...
2007-04-21, 4666👍, 0💬

How To Use an Array as a Queue
How To Use an Array as a Queue? - PHP Script Tips - PHP Built-in Functions for Arrays A queue is a simple data structure that manages data elements following the first-in-first-out rule. You use the following two functions together to use an array as a queue: array_push($array, $value) - Pushes a ne...
2007-04-21, 7372👍, 0💬

How To Merge Values of Two Arrays into a Single Array
How To Merge Values of Two Arrays into a Single Array? - PHP Script Tips - PHP Built-in Functions for Arrays You can use the array_merge() function to merge two arrays into a single array. array_merge() appends all pairs of keys and values of the second array to the end of the first array. Here is a...
2007-04-21, 9002👍, 0💬

How To Join a List of Keys with a List of Values into an Array
How To Join a List of Keys with a List of Values into an Array? - PHP Script Tips - PHP Built-in Functions for Arrays If you have a list keys and a list of values stored separately in two arrays, you can join them into a single array using the array_combine() function. It will make the values of the...
2007-04-21, 6058👍, 0💬

How To Sort an Array by Values
How To Sort an Array by Values? - PHP Script Tips - PHP Built-in Functions for Arrays Sorting an array by values is doable by using the sort() function. It will re-order all pairs of keys and values based on the alphanumeric order of the values. Then it will replace all keys with integer keys sequen...
2007-04-21, 4952👍, 0💬

How To Sort an Array by Keys
How To Sort an Array by Keys? - PHP Script Tips - PHP Built-in Functions for Arrays Sorting an array by keys can be done by using the ksort() function. It will re-order all pairs of keys and values based on the alphanumeric order of the keys. Here is a PHP script on how to use ksort(): <?php ...
2007-04-21, 4800👍, 0💬

How To Get All the Values Out of an Array
How To Get All the Values Out of an Array? - PHP Script Tips - PHP Built-in Functions for Arrays Function array_values() returns a new array that contains all the keys of a given array. Here is a PHP script on how to use array_values(): <?php $mixed = array(); $mixed["Zero"] = "PHP"; $mixed[1...
2007-04-21, 4488👍, 0💬

How To Get All the Keys Out of an Array
How To Get All the Keys Out of an Array? - PHP Script Tips - PHP Built-in Functions for Arrays Function array_keys() returns a new array that contains all the keys of a given array. Here is a PHP script on how to use array_keys(): <?php $mixed = array(); $mixed["Zero"] = "PHP"; $mixed[1] = "P...
2007-04-21, 4492👍, 0💬

How To Find a Specific Value in an Array
How To Find a Specific Value in an Array? - PHP Script Tips - PHP Built-in Functions for Arrays There are two functions can be used to test if a value is defined in an array or not: array_search($value, $array) - Returns the first key of the matching value in the array, if found. Otherwise, it retur...
2007-04-20, 4527👍, 0💬

How Do You If a Key Is Defined in an Array
How Do You If a Key Is Defined in an Array? - PHP Script Tips - PHP Built-in Functions for Arrays There are two functions can be used to test if a key is defined in an array or not: array_key_exists($key, $array) - Returns true if the $key is defined in $array. isset($array[$key]) - Returns true if ...
2007-04-20, 4494👍, 0💬

How To Get the Total Number of Values in an Array
How To Get the Total Number of Values in an Array? - PHP Script Tips - PHP Built-in Functions for Arrays You can get the total number of values in an array by using the count() function. Here is a PHP example script: <?php $array = array("PHP", "Perl", "Java"); print_r("Size 1: ".count($array...
2007-04-20, 4580👍, 0💬

How To Copy Array Values to a List of Variables
How To Copy Array Values to a List of Variables? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations If you want copy all values of an array to a list of variable, you can use the list() construct on the left side of an assignment operator. list() will only take values with integ...
2007-04-20, 4531👍, 0💬

How the Values Are Ordered in an Array
How the Values Are Ordered in an Array? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations PHP says that an array is an ordered map. But how the values are ordered in an array? The answer is simple. Values are stored in the same order as they are inserted like a queue. If you wa...
2007-04-20, 4370👍, 0💬

How to Loop through an Array
How to Loop through an Array? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations The best way to loop through an array is to use the "foreach" statement. There are two forms of "foreach" statements: foreach ($array as $value) {} - This gives you only one temporary variable to ho...
2007-04-20, 4747👍, 0💬

Can You Copy an Array
Can You Copy an Array? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations You can create a new array by copying an existing array using the assignment statement. Note that the new array is not a reference to the old array. If you want a reference variable pointing to the old arr...
2007-04-20, 4481👍, 0💬

Can You Add Values to an Array without a Key
Can You Add Values to an Array without a Key? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations Can You Add Values to an Array with a Key? The answer is yes and no. The answer is yes, because you can add values without specifying any keys. The answer is no, because PHP will add...
2007-04-20, 4672👍, 0💬

How Values in Arrays Are Indexed
How Values in Arrays Are Indexed? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations Values in an array are all indexed their corresponding keys. Because we can use either an integer or a string as a key in an array, we can divide arrays into 3 categories: Numerical Array - All ...
2007-04-20, 4319👍, 0💬

1 2 >   Sort: Rank