<?php $sampleDate = array("Test1", "Test2", "Test3", "Test4"); array_shift($sampleDate); print_r($sampleDate); // Array ( [0] => Test2 [1] => Test3 [2] => Test4 ) . // Test1 will be shifted ?>
Category Archives: PHP
Remove the last element of an array – PHP
<?php $sampleDate = array("Test1", "Test2", "Test3", "Test4"); array_pop($sampleDate); print_r($sampleDate); // Array ( [0] => Test1 [1] => Test2 [2] => Test3 ) . // Test4 will be removed ?>
Replace string with another string – PHP
<?php $name = "Hello Name"; $name =str_replace("Name", "First Name", $name); echo $name; // Hello First Name ?>
Convert the first character of each word in a string into uppercase – PHP
<?php echo ucwords("hello name"); // Hello Name ?>
Convert the first letter into lower case – PHP
<?php echo lcfirst("Name"); // name ?>
Convert the first letter into uppercase – PHP
<?php echo ucfirst("name"); //Name ?>
Convert the string into upper case – PHP
<?php echo strtoupper("name"); // Name ?>
Convert the string into lower case – PHP
<?php echo strtolower("FIRST NAME") //first name ?>
Remove spaces from the beginning and end of a string – PHP
<?php echo trim(" Test "); // Test //Will remove the spaces from the beginning and end ?>
How to read all the keys or a subset of the keys of an array – PHP
<?php $testArray = array(1 => 5, "name" => "First Name"); print_r(array_keys($testArray)); //Array ( [0] => 1 [1] => name ) ?>