Implode() | Turns Array Into String

Before Implode() This is an Array

array(4) { [0]=> string(61) "https://www.christow.blog/wp-content/uploads/2020/12/post.jpg" [1]=> string(60) "https://www.christow.blog/wp-content/uploads/2020/12/get.jpg" [2]=> string(78) "https://www.christow.blog/wp-content/uploads/2020/12/pexels-photo-4197438.jpeg" [3]=> string(70) "https://www.christow.blog/wp-content/uploads/2020/12/blogPhotos-01.jpg" }

After Implode() This is a String

string(272) "https://www.christow.blog/wp-content/uploads/2020/12/post.jpg,https://www.christow.blog/wp-content/uploads/2020/12/get.jpg,https://www.christow.blog/wp-content/uploads/2020/12/pexels-photo-4197438.jpeg,https://www.christow.blog/wp-content/uploads/2020/12/blogPhotos-01.jpg"

Second Implode Example

Array ( [0] => Chris Tow [1] => Reow Reow [2] => Inga Smith )

string(30) "Chris Tow,Reow Reow,Inga Smith"


The code used for index.php is below:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../styles.css">
    <title>PHP: Implode</title>
</head>
<body>

<h1 class="lesson-h1">Implode() | Turns Array Into String</h1>
    
<?php

$images = [
    'https://www.christow.blog/wp-content/uploads/2020/12/post.jpg', 
    'https://www.christow.blog/wp-content/uploads/2020/12/get.jpg', 
    'https://www.christow.blog/wp-content/uploads/2020/12/pexels-photo-4197438.jpeg',
    'https://www.christow.blog/wp-content/uploads/2020/12/blogPhotos-01.jpg'
];

$imploded_images = implode(',', $images);
echo "<h4>Before Implode() This is an Array</h4>";
echo var_dump($images);
echo "<h4>After Implode() This is a String</h4>";
echo var_dump($imploded_images);

$names = ['Chris Tow', 'Reow Reow', 'Inga Smith'];

$imploded_names = implode(',', $names);
echo "<hr><h4>Second Implode Example</h4>";
print_r($names);
echo "<br><br>";
//Now the Array has been turned into one string
echo var_dump($imploded_names);
echo "<br><hr>";

include('../show_code.php');
show_code('index.php');
?>

</body>
</html>