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

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(): &lt;?php $mixed = array(); $mixed["Zero"] = "PHP"; $mixe...
2017-01-21, 1754🔥, 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(): &lt;?php $mixed = array(); $mixed["Zero"] = "PHP"; $mixed[1] = "Perl"; $mixed["Two"] = "Java"; $mixed["3"] = "C+...
2017-01-21, 1585🔥, 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, 4283🔥, 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, 2126🔥, 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, 2114🔥, 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: &lt;?php $array = array("Hello!", "Hi!", "Allo!", "Hallo!"...
2017-01-11, 1809🔥, 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(): &l...
2017-01-11, 1767🔥, 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, 6246🔥, 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, 3132🔥, 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, 2836🔥, 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(): &lt;?php $date = array('0...
2017-01-05, 1658🔥, 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(): &lt;?php $array = array(5, 7, 6, 2, 1, 3, 4, 2); print("Minimum number: ".min($arr...
2016-12-28, 5706🔥, 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, 2727🔥, 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, 1693🔥, 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: &lt;?php function msg() { print("Hello world!\n"); } msg(); ?&gt; Thi...
2016-12-28, 1688🔥, 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: &lt;?p...
2016-12-28, 1517🔥, 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: &lt;?php function swap($a, $b) { ...
2016-12-24, 1613🔥, 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, 1572🔥, 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: &lt;?php function ref_s...
2016-12-24, 1539🔥, 0💬

Variables Are Passed by Values in PHP
How Variables Are Passed Through Arguments? in PHP? Like more of other programming languages, variables are passed through arguments by values, not by references. That means when a variable is passed as an argument, a copy of the value will be passed into the function. Modifying that copy inside the...
2016-12-24, 1523🔥, 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(): &lt;?php function f2c($f) { r...
2016-12-24, 1521🔥, 0💬

Passing Arrays by References to Functions in PHP
How To Pass Arrays By References? in PHP? Like normal variables, you can pass an array by reference into a function by taking a reference of the original array, and passing the reference to the function. Here is a PHP script on how to pass array as reference: &lt;?php function shrink($array) { a...
2016-12-18, 10247🔥, 0💬

Defining an Array Argument as Reference in PHP
Can You Define an Array Argument as a Reference Type? in PHP? You can define an array 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 array argument as a reference type: &lt;?...
2016-12-18, 2525🔥, 0💬

Returning an Array from a Function in PHP
How To Return an Array from a Function? in PHP? You can return an array variable like a normal variable using the return statement. No special syntax needed. Here is a PHP script on how to return an array from a function: &lt;?php function powerBall() { $array = array(rand(1,55), rand(1,55), ran...
2016-12-18, 2275🔥, 0💬

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