<< < 1 2 3 4 5 6 7 8 9 10 > >>   Sort: Rank

Retrieving All Values from an Array in PHP
How To Get All the Values Out of an Array in PHP? Function array_values() returns a new array that contains all the values of a given array. Here is a PHP script on how to use array_values(): <?php $mixed = array(); $mixed["Zero"] = "PHP"; $mixed[1] = "Perl"; $mixed["Two"] = "Java"; $mixed["3"] =...
2017-01-21, 374👍, 0💬

Sorting an Array by Keys in PHP
How To Sort an Array by Keys in PHP? 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 $mixed = array(); $mixed["Zero"] = "PHP"; $mixed[1]...
2017-01-21, 333👍, 0💬

Finding a Given Value in an Array in PHP
How To Find a Specific Value in an Array in PHP? 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 returns false. in_array($value, $array) - Returns tr...
2017-01-21, 316👍, 0💬

Sorting an Array by Values in PHP
How To Sort an Array by Values in PHP? 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 sequentially starting with 0. So using sort() on arra...
2017-01-21, 288👍, 0💬

Retrieving All Keys from an Array in PHP
How To Get All the Keys Out of an Array in PHP? 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] = "Perl"; $mixed["Two"] = "Java"; $mixed["3"] = "C+"; $...
2017-01-21, 288👍, 0💬

Using an Array as a Stack in PHP
How To Use an Array as a Stack in PHP? 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 value to the end of an array. The value will b...
2017-01-11, 363👍, 0💬

Using an Array as a Queue in PHP
How To Use an Array as a Queue in PHP? 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 new value to the end of an array. The value will ...
2017-01-11, 338👍, 0💬

Joining Keys and Values into an Array in PHP
How To Join a List of Keys with a List of Values into an Array in PHP? 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 first array to be the keys of the resulting ar...
2017-01-11, 328👍, 0💬

Randomly Retrieving Array Values in PHP
How To Randomly Retrieve a Value from an Array in PHP? 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 $array = array("Hello!", "Hi!", "Allo!", "Hallo!", "C...
2017-01-11, 295👍, 0💬

Merging Two Arrays into a Single Array in PHP
How To Merge Values of Two Arrays into a Single Array in PHP? 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 PHP script on how to use array_merge(): <?p...
2017-01-11, 276👍, 0💬

Looping through an Array without "foreach" in PHP
How To Loop through an Array without Using "foreach" in PHP? PHP offers the following functions to allow you loop through an array without using the "foreach" statement: reset($array) - Moves the array internal pointer to the first value of the array and returns that value. end($array) - Moves the a...
2017-01-05, 398👍, 0💬

Creating an Array with a Sequence in PHP
How To Create an Array with a Sequence of Integers or Characters in PHP? 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 character, and ending with the second integer or c...
2017-01-05, 332👍, 0💬

Padding an Array with a Given Value in PHP
How To Pad an Array with the Same Value Multiple Times in PHP? 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 positive, it will pad to the end of the array. If ...
2017-01-05, 329👍, 0💬

Truncating an Array in PHP
How To Truncate an Array in PHP? 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 counted from the beginning of the array. If negativ...
2017-01-05, 300👍, 0💬

Joining Array Values into a Single String in PHP
How To Join Multiple Strings Stored in an Array into a Single String in PHP? 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 to use implode(): <?php $date = array('01', ...
2017-01-05, 285👍, 0💬

Creating Your Own Functions in PHP
Where to find tutorials on how to create Your Own Functions in PHP? A collection of tutorials to answer many frequently asked questions on Creating Your Own Functions in PHP. Topics included in this collection are: Defining a User Function in PHP Invoking a User Function in PHP Returning a Value fro...
2016-12-28, 437👍, 0💬

Invoking a User Function in PHP
How To Invoke a User Function? in PHP? You can invoke a function by entering the function name followed by a pair of parentheses. If needed, function arguments can be specified as a list of expressions enclosed in parentheses. Here is a PHP script example on how to invoke a user function: <?php f...
2016-12-28, 294👍, 0💬

Getting Minimum/Maximum Value of an Array in PHP
How To Get the Minimum or Maximum Value of an Array in PHP? 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, 1, 3, 4, 2); print("Minimum number: ".min($array)....
2016-12-28, 293👍, 0💬

Defining a User Function in PHP
How To Define a User Function? in PHP? You can define a user function anywhere in a PHP script using the function statement like this: "function name() {...}". Here is a PHP script example on how to define a user function: <?php function msg() { print("Hello world!\n"); } msg(); ?> This script...
2016-12-28, 292👍, 0💬

Splitting a String into an Array in PHP
How To Split a String into an Array of Substring in PHP? 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) - Splitting a string based on a regular express...
2016-12-28, 284👍, 0💬

Passing an Argument to a Function in PHP
How To Pass an Argument to a Function? in PHP? To pass an argument to a function, you need to: Add an argument definition in the function definition. Add a value as an argument when invoking the function. Here is a PHP script on how to use arguments in a function(): <?php function f2c($f) { retur...
2016-12-24, 324👍, 0💬

Defining an Argument as a Reference in PHP
Can You Define an Argument as a Reference Type? in PHP? You can define an argument as a reference type in the function definition. This will automatically convert the calling arguments into references. Here is a PHP script on how to define an argument as a reference type: <?php function ref_swap(...
2016-12-24, 321👍, 0💬

Returning a Value from a Function in PHP
How To Return a Value Back to the Function Caller? in PHP? You can return a value to the function caller by using the "return $value" statement. Execution control will be transferred to the caller immediately after the return statement. If there are other statements in the function after the return ...
2016-12-24, 285👍, 0💬

Passing Variables by References in PHP
How To Pass Variables By References? in PHP? You can pass a variable by reference to a function by taking the reference of the original variable, and passing that reference as the calling argument. Here is a PHP script on how to use pass variables by references: <?php function swap($a, $b) { $t =...
2016-12-24, 277👍, 0💬

<< < 1 2 3 4 5 6 7 8 9 10 > >>   Sort: Rank