How can the PHP function printDataHorizontal be modified to display the image names stored in the array in a more visually appealing manner?
The issue is that the printDataHorizontal function currently displays the image names in a simple horizontal list, which may not be visually appealing. To make it more visually appealing, we can modify the function to display the image names in a grid or a styled list format.
function printDataHorizontal($imageArray) {
echo '<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;">';
foreach ($imageArray as $imageName) {
echo '<div style="border: 1px solid #ccc; padding: 10px; text-align: center;">';
echo '<img src="' . $imageName . '" alt="' . $imageName . '" style="max-width: 100px; max-height: 100px;"><br>';
echo $imageName;
echo '</div>';
}
echo '</div>';
}
// Example usage
$imageArray = ['image1.jpg', 'image2.jpg', 'image3.jpg'];
printDataHorizontal($imageArray);
Related Questions
- What is the error message "mysql_fetch_assoc() expects parameter 1 to be resource, boolean given" indicating in the PHP code provided?
- What are the potential pitfalls of using the mysql_query function in PHP?
- What is the purpose of using the count() function in PHP and what are common scenarios where it is used?