<< < 50 51 52 53 54 55 56 57 58 59 60 > >>   Sort: Rank

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, 6242🔥, 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, 3129🔥, 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, 2835🔥, 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, 1657🔥, 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, 5705🔥, 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, 1611🔥, 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, 1538🔥, 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, 10241🔥, 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, 2274🔥, 0💬

Passing Arrays by Values to Functions in PHP
How Arrays Are Passed Through Arguments? in PHP? Like a normal variable, an array is passed through an argument by value, not by reference. That means when an array is passed as an argument, a copy of the array will be passed into the function. Modifying that copy inside the function will not impact...
2016-12-18, 1737🔥, 0💬

Accessing Global Variables inside a Function in PHP
How To Access a Global Variable inside a Function? in PHP? By default, global variables are not accessible inside a function. However, you can make them accessible by declare them as "global" inside a function. Here is a PHP script on declaring "global" variables: &lt;?php ?&gt; $intRate = 5...
2016-12-08, 4552🔥, 0💬

Returning a Reference from a Function in PHP
How To Return a Reference from a Function? in PHP? To return a reference from a function, you need to: Add the reference operator "&amp;" when defining the function. Add the reference operator "&amp;" when invoking the function. Here is a PHP script on how to return a reference from a functi...
2016-12-08, 1886🔥, 0💬

Function Returns Data by Value in PHP
How Values Are Returned from Functions? in PHP? If a value is returned from a function, it is returned by value, not by reference. That means that a copy of the value is return. Here is a PHP script on how values are returned from a function: &lt;?php $favor = "vbulletin"; function getFavor() { ...
2016-12-08, 1641🔥, 0💬

Local Variables in a Function in PHP
What Is the Scope of a Variable Defined in a Function? in PHP? The scope of a local variable defined in a function is limited with that function. Once the function is ended, its local variables are also removed. So you can not access any local variable outside its defining function. Here is a PHP sc...
2016-12-08, 1632🔥, 0💬

Global Variables in Main Script in PHP
What Is the Scope of a Variable Defined outside a Function? in PHP? A variable defined outside any functions in main script body is called global variable. However, a global variable is not really accessible globally any in the script. The scope of global variable is limited to all statements outsid...
2016-12-08, 1529🔥, 0💬

Reading the Entire File to a String in PHP
How To Read the Entire File into a Single String in PHP? If you have a file, and you want to read the entire file into a single string, you can use the file_get_contents() function. It opens the specified file, reads all characters in the file, and returns them in a single string. Here is a PHP scri...
2016-12-04, 3091🔥, 0💬

<< < 50 51 52 53 54 55 56 57 58 59 60 > >>   Sort: Rank