The code below successfully print an array result of all the php files in a folder.
$search_data = glob('download/*.php');
print_r($search_data);
Below is the Array Result
Array ( [0] => download/index.php
[1] => download/register.php )
Here is my question: Please How do I print all the files.
I have tried adding the code below but it throws error
Uncaught TypeError: json_decode(): Argument #1 ($json) must be of type string, array given
$json = json_decode($search_data, true);
foreach ($json as $data) {
//print or list all the files
echo $files = $data;
echo "<br>";
}
>Solution :
$search_data isn’t a json string to decode. It’s already an array. You’d just loop through it normally. Then use echo "$data<br>\n";
Thus you’d have:
$search_data = glob('download/*.php');
foreach ($search_data as $data) {
echo "$data<br>\n";
}