How to show all the multidimensional array in PHP?
I'm trying to print a multidimensional array in PHP but I not getting how to do it.
Here开发者_运维百科 is the code:
foreach ($srcs as $img64) {
// Vou agora apanhar a imagem e registar as suas caracteristicas
$image = file_get_contents($img64);
$details_images = getimagesize($img64);
$image_type = pathinfo($img64, PATHINFO_EXTENSION);
// Vou converter para base64
$imgbase64[] .= array(
"base64" => base64_encode($image),
"image_type" => $image_type
);
}
If I print_r()
the $imgbase64
I got this:
Array
(
[0] => Array
[1] => Array
[2] => Array
[3] => Array
[4] => Array
[5] => Array
[6] => Array
[7] => Array
[8] => Array
)
How can I print the values where is the array?
If you can give me any clue, will be appreciated.
Best Regards,
Use:
$imgbase64[] = array(
Instead of:
$imgbase64[] .= array(
.=
is the concatenation operator, which will cast the array to a string that literally just says "Array"
.
You're using string concatenation where you should not:
$imgbase64[] .= array(
"base64" => base64_encode($image),
"image_type" => $image_type
);
That's why it's assigning the string value of Array
to your elements. Remove the period so it is:
$imgbase64[] = array(
"base64" => base64_encode($image),
"image_type" => $image_type
);
Slightly off-topic (but a useful tip, so here it is).
If you simply want to output the data for debugging purposes, var_dump is a better solution than print_r, as it'll recursively iterate over the data in question.
精彩评论