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

Uploading Files into Database in PHP
How To Upload Files into Database in PHP? To store uploaded files to MySQL database, you can use the normal SELECT statement as shown in the modified processing_uploaded_files.php listed below: <?php $con = mysql_connect("localhost", "", ""); mysql_select_db("fyi"); $error = $_FILES['fyicenter_lo...
2017-02-20, 400👍, 1💬

💬 2017-02-20 Jonas: Thanks for the sample code!

Adding Values to an Array without Keys in PHP
Can You Add Values to an Array without Keys in PHP? 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 a default integer key for you if you are not specifying a key. PH...
2017-02-03, 414👍, 0💬

Copying an Array in PHP
Can You Copy an Array in PHP? 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 array, you can use the reference operator "&". Here is a PHP scr...
2017-02-03, 401👍, 0💬

Data Types of Array Keys in PHP
What Types of Data Can Be Used as Array Keys in PHP? Two types of data can be used as array keys: string and integer. When a string is used as a key and the string represent an integer, PHP will convert the string into a integer and use it as the key. Here is a PHP script on different types of keys:...
2017-02-03, 348👍, 0💬

Index of Array Values in PHP
How Values in Arrays Are Indexed in PHP? 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 keys are sequential integers. Associative Array - All keys are st...
2017-02-03, 320👍, 0💬

Looping through an Array in PHP
How to Loop through an Array in PHP? 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 hold the current value in the array. foreach ($array as $key=>$v...
2017-02-03, 308👍, 0💬

PHP Built-in Functions for Arrays
Where to find tutorials on how to use PHP built-in functions to manage arrays? A collection of tutorials to answer many frequently asked questions on how to PHP functions to manage arrays. Clear answers are provided with tutorial exercises on searching keys and values, sorting arrays, merging two ar...
2017-01-29, 469👍, 0💬

Copying Array Values to a List of Variables in PHP
How To Copy Array Values to a List of Variables in PHP? 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 integer keys starting from 0. Here is a PHP script on how to use list(...
2017-01-29, 346👍, 0💬

Counting the Number of Values in an Array in PHP
How To Get the Total Number of Values in an Array in PHP? 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)."\n"); $array = array(); print_r("Size 2: ".count...
2017-01-29, 340👍, 0💬

Order of Array Values in PHP
How the Values Are Ordered in an Array in PHP? 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 want to reorder them differently, you need to use a sort function. ...
2017-01-29, 318👍, 0💬

Verifying If a Key Exists in an Array in PHP
How Do You Know If a Key Is Defined in an Array in PHP? 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 the $key is defined in $array. Here is a P...
2017-01-29, 308👍, 0💬

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, 429👍, 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, 349👍, 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, 339👍, 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, 306👍, 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, 306👍, 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, 417👍, 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, 388👍, 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, 350👍, 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, 315👍, 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, 291👍, 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, 462👍, 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, 374👍, 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, 349👍, 0💬

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