$str = "123";
$int = intval($str);
echo $int; // Output: 123
$int = 123;
$str = strval($int);
echo $str; // Output: "123"
$array = array("apple", "banana", "orange");
$str = implode(", ", $array);
echo $str; // Output: "apple, banana, orange"
$str = "apple, banana, orange";
$array = explode(", ", $str);
print_r($array); // Output: Array ( [0] => apple [1] => banana [2] => orange )
$str = "3.14";
$float = floatval($str);
echo $float; // Output: 3.14
$float = 3.14;
$int = intval($float);
echo $int; // Output: 3
$date_str = "2022-01-01 12:00:00";
$timestamp = strtotime($date_str);
echo $timestamp; // Output: 1641043200
$timestamp = 1641043200;
$date_str = date("Y-m-d H:i:s", $timestamp);
echo $date_str; // Output: "2022-01-01 12:00:00"
The above are commonly used PHP data conversion functions with examples. Mastering these functions allows flexible handling of different data types and improves development efficiency. Whether converting strings, arrays, types, or time values, these functions are essential tools for both beginners and advanced PHP developers to reference and learn.