
Saggi
Members-
Posts
10 -
Joined
-
Last visited
Profile Information
-
Gender
Male
Saggi's Achievements

Member (2/5)
0
Reputation
-
Convert a string from 12hour time format to 24hour format
Saggi replied to Saggi's topic in PHP Coding Help
I did. Thanks. -
Convert a string from 12hour time format to 24hour format
Saggi replied to Saggi's topic in PHP Coding Help
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. -
Convert a string from 12hour time format to 24hour format
Saggi replied to Saggi's topic in PHP Coding Help
function convertTimeFormat($time12Hour){ echo date("H:i:s:A", strtotime("06:40:03 PM")); } $time12Hour="06:40:03PM"; echo $result=convertTimeFormat($time12Hour); -
Convert a string from 12hour time format to 24hour format
Saggi replied to Saggi's topic in PHP Coding Help
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); -
Convert a string from 12hour time format to 24hour format
Saggi replied to Saggi's topic in PHP Coding Help
Though that's plausible but I try not to use date-related functions and formatting types. -
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"; */
-
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);
-
$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 )
-
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,
-
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);