Jump to content

Saggi

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by Saggi

  1. I want to learn PHP the hard way. lol. Anyway, I finished the task by both using in built and traditional way. Thanks for the input. Appreciate it.
  2. function convertTimeFormat($time12Hour){ echo date("H:i:s:A", strtotime("06:40:03 PM")); } $time12Hour="06:40:03PM"; echo $result=convertTimeFormat($time12Hour);
  3. function convertTimeFormat($time12Hour) { $time24Hour = ""; $Split = explode(":",$time12Hour); $Hour = $Split[0]; // $Minutes = $Split[1]; // $Seconds = $Split[2]; $Split[2] = substr($Split[2],0,2); if($Hour == '12' && strpos($time12Hour,"AM")!== FALSE) { } elseif(strpos($time12Hour,"PM")!== FALSE && $Hour != "12") { } elseif($Hour != "12" && strpos($time12Hour,"AM")!== FALSE) { echo $convertHour = 12+$Hour.":".$Split[1].":".$Split[2]."PM"; } return $time24Hour; } $time12Hour = "06:40:03AM"; $result = convertTimeFormat($time12Hour);
  4. Though that's plausible but I try not to use date-related functions and formatting types.
  5. Hello All, Need an advise in finishing this task please. function convertTimeFormat($time12Hour) { // Initialized required variable to an empty string. $time24Hour = ""; // Used explode() function to break the string into an array and stored its value in $Split variable. $Split = explode(":",$time12Hour); // print_r(explode (":", $time12Hour)); => Array ( [0] => 09 [1] => 50 [2] => 08AM ) // Retrieved only "hour" from the array and stored in $Hour variable. $Hour = $Split[0]; $Split[2] = substr($Split[2],0,2); // Used stripos() function to find the position of the first occurrence of a string inside another string. if($Hour == '12' && strpos($time12Hour,"AM")!== FALSE) { // Code here } elseif(strpos($time12Hour,"PM")!== FALSE && $Hour != "12") { // code here } return $time24Hour; } $time12Hour = "09:50:08AM"; $result = convertTimeFormat($time12Hour); print_r($result); /* Input : "09:50:08AM"; Output : "21:50:08PM"; */
  6. I tried without using array_reverse and Here is my other solution: $fruits = ["Mango","Strawberry","Bananas","Pineapple"]; function reverseArray($Arr) { $fruitsReverse = []; for($i=count($Arr)-1; $i>=0; $i--) { array_push($fruitsReverse,$Arr[$i]); } return $fruitsReverse; } $result = reverseArray($fruits); print_r($result);
  7. $fruits = ["Mango","Strawberry","Bananas","Pineapple"]; function reverseArray($Arr) { return array_reverse($Arr); } $result = reverseArray($fruits); print_r($result); Output: Array ( [0] => Pineapple [1] => Bananas [2] => Strawberry [3] => Mango )
  8. Hi all, Need help in solving this task using PHP built in function : array_reverse() and without it. Appreciate it in explaining the code as I'm completely a newbie. function reverseArray($Arr) { } $fruits = ["Mango","Strawberry","Bananas","Pineapple"]; $result = reverseArray($fruits); Many thanks,
  9. Hello all, Noob here 😑. Need help in solving this task. I Wrote a function which returns a factorial number but how to pass the logic that the passing parameter must be an integer. Also, if any other data type is passed, function should return error “Please provide correct data type”. Many thanks, function fact ($x) { if($x <= 1) { return 1; } else { return $x * fact($x - 1); } } echo fact(3);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.