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

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, 1715🔥, 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, 4474🔥, 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, 1867🔥, 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, 1606🔥, 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, 1602🔥, 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, 1510🔥, 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, 3024🔥, 0💬

Specifying Argument Default Values in PHP
How To Specify Argument Default Values? in PHP? If you want to allow the caller to skip an argument when calling a function, you can define the argument with a default value when defining the function. Adding a default value to an argument can be done like this "function name($arg=expression){}. Her...
2016-12-04, 1893🔥, 0💬

Function with Undefined Number of Arguments in PHP
How To Define a Function with Any Number of Arguments? in PHP? If you want to define a function with any number of arguments, you need to: Declare the function with no argument. Call func_num_args() in the function to get the number of the arguments. Call func_get_args() in the function to get all t...
2016-12-04, 1537🔥, 0💬

Reading a Text File to an Array in PHP
How To Read a Text File into an Array in PHP? If you have a text file with multiple lines, and you want to read those lines into an array, you can use the file() function. It opens the specified file, reads all the lines, puts each line as a value in an array, and returns the array to you. Here is a...
2016-12-04, 1501🔥, 0💬

Opening a File for Writing in PHP
How To Open a File for Writing in PHP? If you want to open a new file and write date to the file, you can use the fopen($fileName, "w") function. It creates the specified file, and returns a file handle. The second argument "w" tells PHP to open the file for writing. Once the file is open, you can u...
2016-12-02, 1505🔥, 0💬

Reading One Line of Text from a File in PHP
How To Read One Line of Text from a File in PHP? If you have a text file with multiple lines, and you want to read those lines one line at a time, you can use the fgets() function. It reads the current line up to the "\n" character, moves the file pointer to the next line, and returns the text line ...
2016-12-02, 2366🔥, 0💬

Reading One Character from a File in PHP
How To Read One Character from a File in PHP? If you have a text file, and you want to read the file one character at a time, you can use the fgetc() function. It reads the current character, moves the file pointer to the next character, and returns the character as a string. If end of the file is r...
2016-12-02, 1604🔥, 0💬

Appending Data to the End of a File in PHP
How To Append New Data to the End of a File in PHP? If you have an existing file, and want to write more data to the end of the file, you can use the fopen($fileName, "a") function. It opens the specified file, moves the file pointer to the end of the file, and returns a file handle. The second argu...
2016-12-02, 1552🔥, 0💬

Opening a file for Reading in PHP
How To Open a File for Reading in PHP? If you want to open a file and read its contents piece by piece, you can use the fopen($fileName, "r") function. It opens the specified file, and returns a file handle. The second argument "r" tells PHP to open the file for reading. Once the file is open, you c...
2016-12-02, 1409🔥, 0💬

Issue with "while ($c=fgetc($f))" Loop in PHP
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to loop through each character in a file, the loop may end in the middle of the file when there is a "0" character, because PHP treats "0" as Boolean false. To properly loop to the end of the file, you sho...
2016-11-27, 3367🔥, 0💬

Writing a String to a File with a File Handle in PHP
How To Write a String to a File with a File Handle in PHP? If you have a file handle linked to a file opened for writing, and you want to write a string to the file, you can use the fwrite() function. It will write the string to the file where the file pointer is located, and moves the file pointer ...
2016-11-27, 2008🔥, 0💬

Writing a String to a File without a File Handle in PHP
How To Write a String to a File without a File Handle in PHP? If you have a string, want to write it to a file, and you don't want to open the file with a file handle, you can use the file_put_contents(). It opens the specified file, writes the specified string, closes the file, and returns the numb...
2016-11-27, 1786🔥, 0💬

Writing an Array to a File without File Handle in PHP
How To Write an Array to a File without a File Handle in PHP? If you have an array, want to write it to a file, and you don't want to open the file with a file handle, you can use the file_put_contents(). It opens the specified file, writes all values from the specified string, closes the file, and ...
2016-11-27, 1513🔥, 0💬

Opening Standard Output as a File Handle in PHP
How To Open Standard Output as a File Handle in PHP? If you want to open the standard output as a file handle yourself, you can use the fopen("php://stdout") function. It creates a special file handle linking to the standard output, and returns the file handle. Once the standard output is opened to ...
2016-11-24, 4598🔥, 0💬

Creating a Directory in PHP
How To Create a Directory in PHP? You can use the mkdir() function to create a directory. Here is a PHP script example on how to use mkdir(): &lt;?php if (file_exists("/temp/download") ){ print("Directory already exists.\n"); } else { mkdir("/temp/download"); print("Directory created.\n"); } ?&a...
2016-11-24, 2147🔥, 0💬

Working with Directories and Files in PHP
Where to find tutorials on how to Work with Directories and Files in PHP? A collection of tutorials to answer many frequently asked questions on how to Work with Directories and Files in PHP. Topics included in this collection are: Creating a Directory in PHP Removing an Empty Directory in PHP Remov...
2016-11-24, 1675🔥, 0💬

Removing an Empty Directory in PHP
How To Remove an Empty Directory in PHP? If you have an empty existing directory and you want to remove it, you can use the rmdir(). Here is a PHP script example on how to use rmdir(): &lt;?php if (file_exists("/temp/download") ){ rmdir("/temp/download"); print("Directory removed.\n"); } else { ...
2016-11-24, 1382🔥, 0💬

Putting Directory Entries into an Array in PHP
How To Dump the Contents of a Directory into an Array in PHP? If you want to get the contents of a directory into an array, you can use the scandir() function. It gets a list of all the files and sub directories of the specified directory and returns the list as an array. The returning list also inc...
2016-11-20, 1709🔥, 0💬

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