X
X
Xrist1An2014-09-13 03:13:10
PHP
Xrist1An, 2014-09-13 03:13:10

How to create and display such a PHP array?

Seems like a simple task, but I'm stuck. So first I create an associative array:

foreach ($photo_arr as $photo) {
$arr = array(
'mini' => 'thumbs/'.$photo, // адрес к миниатюрке фото
'big' => 'full/'.$photo //адрес к полноразмерному изображению
);
}

Okay, I'm not sure if I did it correctly (correct me if something is wrong). Now let's move on to its output, but you need to do it in the following construction:
<? foreach ($arr as $k => $val) { ?>
  <a href="<?=$val['big']?>">
    <img src="<?=$val['mini']?>">
  </a>
<? } ?>

Well, here I generally don’t understand well whether I got it or not, but I hope you understand what I want to do. Actually the question is: what's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
unclechu, 2014-09-13
@Xrist1An

<a href="<?=$arr['big']?>">
  <img src="<?=$arr['mini']?>">
</a>

With foreach you iterate over this associative array, where on each iteration $k is the key ('mini', 'big') and $val is the key value ('thumbs/'.$photo, 'full/'.$ photo).
That is, foreach is simply not needed.
UPD: but judging by the first piece of code (incl. telepathy mode), you seem to want to fill the $arr array with other associative arrays, then:
<?
$arr = array();

foreach ($photo_arr as $photo) {
  $arr[] = array(
    'mini' => 'thumbs/'.$photo, // адрес к миниатюрке фото
    'big' => 'full/'.$photo //адрес к полноразмерному изображению
  );
}
?>

<? foreach ($arr as $item) { ?>
  <a href="<?=$item['big']?>">
    <img src="<?=$item['mini']?>">
  </a>
<? } ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question