F
F
felony13twelve2020-05-13 14:05:42
PHP
felony13twelve, 2020-05-13 14:05:42

How to collect values ​​in one line and output?

Ku! Please help, how to collect the value in one line and display it?

$arr = array("gd" => 3, "hedh" => 0);
arsort($arr);
$plat = 1;
foreach ($arr as $key => $val ) {
  $text = "{$place} - {$key}: {$val}"; 
  //$text - это не правильно 
  $plat++;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Q
qwermus, 2020-05-13
@felony13twelve

$arr = array("gd" => 3, "hedh" => 0);
arsort($arr);
$plat = 1;
$text = '';
foreach ($arr as $key => $val ) {
  $text = $text." ".$place." - ".$key.": ".$val; 
  //$text - это не правильно 
  $plat++;
}
echo $text;

I
Ivan Ivanov, 2020-05-13
@maksim_fix

Read about the concatenation operator, if I understood you correctly.
$text = $place . ' - ' . $key . ': ' . $val;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question