John Davidson

Variable type of "mon" in PHP getdate() is INT but echoes as STRING

0 comments
Message:


I'm a beginner re-learning to code and building a simple "dashboard" in PHP. I constructed a database with information about my friends, including their date of birth and I want my dashboard to tell me, if any of my friends has birthday that given day.


So far I've managed to extract today's date and display it (I apologize for the switch, it was the only thing I was able to come up with):


//Date
$today = getdate();

foreach ($today as $key => $value) {
switch ($key) {
case "mday":
$day = $value;
echo "Today is " . $value;
break;
case "month":
echo " " . $value;
echo "<br />";
case "mon":
$mon = $value;
break;
}
}

echo $mon;
echo $day;

BUT as in my db the date_of_birth format reads as string (e.g. 1987-02-14) in need a numeric value for month. It should be "mon", as both in the documentation and when I var_dump $today "mon" is supposed to be numeric value/int. But no. When echoed it echoes "February".


Why? Why is that? What am I missing? I will be grateful for any advice.



My Answer:
Variable type refers to the classification of a variable based on the type of data it represents. Common variable types include:

1. Numeric variables: These variables represent numerical data and can be further classified as integer or floating-point numbers.

2. Character variables: These variables represent text data, such as names, addresses, or descriptions.

3. Boolean variables: These variables represent binary data, typically taking on values of true or false.

4. Date/time variables: These variables represent dates and times, allowing for calculations and comparisons based on temporal data.

5. Categorical variables: These variables represent data that falls into distinct categories or groups, such as gender, color, or type of product.

6. Ordinal variables: These variables represent data that has a natural order or ranking, such as ratings or levels of education.

Understanding the variable type is important for data analysis and programming, as it determines the operations that can be performed on the data and the appropriate methods for analyzing and visualizing it.

Rate this post

3 of 5 based on 7766 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us