0
there is how to put 2 arrays in the same foreach?
Let me explain what I need, I’m using the Wideimage class to resize the images, I need to grab the image extension to save it later. My problem is there, how can I get the extension of each image of the array?
I can even do with a foreach like that:
foreach ($image as $imagem) {
foreach ($imagemExtensao as $extensao) {
$extensaoDaImagem = pathinfo($extensao, PATHINFO_EXTENSION);
$imagemFinal = $imagem->resize(400, 300);
$geraNome = md5(time().rand());
$imagemFinal->saveToFile('imagens/usuarios/' . $geraNome .'.'.$extensaoDaImagem);
$nomeCompleto = $geraNome.'.'.$extensaoDaImagem;
}
}
Only then it duplicates the images, the names, everything. So I need to do it once, or if you have another idea.
Provide an example of the structure of
array
s returned by the class, so we understand whether it is two-dimensional or two isolated, whether it is of the typeassoc
orindex
. Details like this will make you get faster answers :)– Guilherme Nascimento
I use the Wideimage function to bring the image array follows function, $image = Wideimage::loadFromUpload('image', 'image.php'); Then I need to use another variable to bring the array with the names, to later take the image extension, $imageExtensao = $_FILES['image']['name']; so I need the foreach, to be able to scan the 2 arrays at the same time.
– Eduardo Paludo
Do not use comments, edit the question, ask the question and provide the format of
arrays
(you can capture such format usingprint_r
).– Guilherme Nascimento
So you already have an array of extensions, is that it? And it has the same size as the image array? Are the indexes of the two arrays matching? For example, the image in
$image[5]
is the owner of the$imagemExtensao[5]
?– bfavaretto
Yeah, that’s right.
– Eduardo Paludo