PHP function of the day: array_rand()

For day 20 of 21 in the “PHP Function of the day” series, I’m going to look at array_rand().  The function takes a required array and an optional number of random keys to return.  It returns a random key (not the value). Let’s take a look. <?php $names = array(“Joe”,”Jim”,”Sarah”,”Jill”); $numbers = array(1,2,3,4,5,6,7,8,9); $names_rand_keys = array_rand($names,3); $numbers_rand_keys …

Continue reading "PHP function of the day: array_rand()"

PHP function of the day: date_diff()

For day 19 of 21 in the “PHP Function of the day” series, I’m going to look at date_diff(). Let’s take a look. <?php $shoppingDay=date_create(“2020-05-28”); $payDay=date_create(“2020-06-01”); $difference = date_diff($shoppingDay,$payDay); print_r($difference); echo “<br /><br />”.$difference->format(“%R%a days”); ?>   See the output   As you an see, this calculates the difference between two dates (something that could be pretty …

Continue reading "PHP function of the day: date_diff()"

PHP function of the day: array_flip()

For day 15 of 21 in the “PHP Function of the day” series, I’m going to look at array_flip(). As you might guess, this function “flips” the array so that the key is the value and the value is the key. Let’s take a look. <?php $joe = array(“fname”=>”Joe”,”lname”=>”Steinbring”,”website”=>”jws.dev”); print_r($joe); echo(“<br />”); print_r(array_flip($joe)); echo(“<br /><br />”); $foods …

Continue reading "PHP function of the day: array_flip()"

PHP function of the day: date()

For day 14 of 21 in the “PHP Function of the day” series, I’m going to look at date(). The function takes a required format and an optional timestamp and outputs a formatted date. Let’s take a look. <?php echo “This is the “.date(“d”).”th day of the month.”.”<br />”; echo “This is the “.date(“m”).”th month of the …

Continue reading "PHP function of the day: date()"

PHP function of the day: rand()

For day 13 of 21 in the “PHP Function of the day” series, I’m going to look at rand(). This function generates a random integer.  You can feed it a minimum value and a maximum value or let it generate a value without the limits. Let’s take a look. <?php echo(rand().'<br />’); echo(rand().'<br />’); echo(rand(0,9)); ?>   …

Continue reading "PHP function of the day: rand()"