J
J
Jony13372016-10-22 19:12:31
PHP
Jony1337, 2016-10-22 19:12:31

How to write different values ​​in two variables from for in php?

hello
i have this code

$arr = array ('imgk','imgkk');
for ($i=0;$i < count($arr);++$i) {
$x = $arr [$i];
$FileName = $_FILES[$x]['name'];
$TempName = $_FILES[$x]['tmp_name'];
$length = 15;
  $chars = 'abdefhiknrstyzABDEFGHKNQRSTYZ23456789';
  $numChars = strlen($chars);
  $string = '';
  for ($ik = 0; $ik < $length; $ik++) {
    $string .= substr($chars, rand(1, $numChars) - 1, 1);
  }
 $final = $string.".png";
 $finalTwo = 'img/'.$final;
include_once('classSimpleImage.php');
   $image = new SimpleImage();
   $image->load($TempName);
   $image->resizeToWidth(250);
   $image->save($finalTwo); 
}

how to make $adImage1 have the first value $finalTwo and $adImage2 the second value $finalTwo
So the code generates random names for photos, For will be executed 2 times, that is, it should be something like this:
$adImage1 = $finalTwo (the value of the first execution of For )
$adImage2 = $finalTwo (the value of the second execution of For)
something like this, is it possible to do in PHP or not if yes I will be glad to any advice

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coderisimo, 2016-10-22
@Jony1337

just ideas.
What if you just use an array?

$finalTwo = [];
//................. твой код
$finalTwo[] = 'img/'.$final;

then $finalTwo[0] is the first value, $finalTwo[1] is the second.
if you need variables, then, I think you can like this:
$finalTwo = []; 
//****************твой код
$finalTwo['adImage'. ($i+1)] = 'img/'.$final;

why use extract() - it will make variables from the array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question