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()"

I tried to do a roadtrip in the new electric car

Last week, I drove from Milwaukee to Madison and back again in the new car.  The 2016 e-Golf has a stated range of 83 miles between charges.  I wanted to see what that looks like in real life. A level 2 charger needs roughly four hours to fully charge the battery.  A level 3 charger …

Continue reading "I tried to do a roadtrip in the new electric car"

PHP function of the day: printf()

For day 16 of 21 in the “PHP Function of the day” series, I’m going to look at printf(). This one is pretty interesting.  It allows you to define a format and a series of arguments.  The “%[something]” in the format string is used to define both where the argument’s value is output and the expected format.  …

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

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()"

PHP function of the day: md5()

For day 12 of 21 in the “PHP Function of the day” series, I’m going to look at md5(). This function calculates the md5 hash of the string you supply as input. Let’s take a look. <?php $input = “Joe is here”; echo md5($input).”</br >”; $input = “Joe was here”; echo md5($input).”</br >”; $input = “Joe is …

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