PHP array

Image
  An array stores multiple values in one single variable. In PHP, the array() function is used to create an array. Example: <?php $pets = array ( "dog" , "cat" , "rabbit" ); echo $pets [ 0 ] . "," . $pets [ 1 ] . "," . $pets [ 2 ]; ?> Output: dog,cat,rabbit An array is a special variable, which can hold more than one value at a time. If you have a list of student names, storing the names in single variables could like this, $name1 = "Peter" $name2 = "Mickle" $name2 = "Bravo" However, what if you want to loop through the names and find a specific one? And what if you had 3 names, but 1000? The solution is to create an array . An array can hold many values under a single name, and you can access the values by referring to an index number. There are three different kind of arrays. Numeric array – Arrays with a numeric index Associative array – Arrays with named keys

Simple Validation

Simple Validation

While you can certainly create your own fancy regular expression tests to validate common strings such as an email address, IP address or URL, it is much simpler to rely on the built-in capabilities of the filter_var() function instead. By passing the appropriate FILTER_ constant, you can easily validate a wide assortment of input values with only a single line of code.

Syntax:
<?php 
// Return 'phpcodinghelper@gmail.com', a valid email address 
echo filter_var("phpcodinghelper@gmail.com",FILTER_VALIDATE_EMAIL);

// Return '192.168.10.10', a valid IP
echo filter_var("192.168.10.10",FILTER_VALIDATE_IP);

// Return 'https://phpcodinghelper.blogspot.com/', a valid URL
echo filter_var("https://phpcodinghelper.blogspot.com/",FILTER_VALIDATE_URL);
?>	

Comments

Popular posts from this blog

PHP Code for get Client IP Address

PHP explode function

PHP Script for MySqli Database Connection