There is such code:

Foreach ($_SESSION[explode] as $explode) { $tr[] = '<td>'. $explode[name].'</td>' <td>'. $explode[filial].'</td>' } 

So, like after a group of values $explode[filial]

Look what conclusion you need: $ explode [filial] contains an array of branches, then

  Город1 Город1 Город1 

Here below we summarize and display the same: Город1 Next:

  Город2 Город2 Город2 

Here below, we summarize and display the same: Город2

And so on.

  • Rephrase the question, give a more detailed example and input data. While it is completely incomprehensible what you need - apelsinka223
  • Done, once again, add safely the list of homogeneous data from the array, and you need to output at the end exactly 1 value, equal to the name of this group, namely the $ explode [filial] group - Mr. Nomov

1 answer 1

For a start, you have an extra apostrophe in the code between '' ', which means that it will no longer be executed in this form. If $ explode [filial] is an array, then I understand you need something like

 <?php //Исх. даннные $_SESSION['explode'] = array( array( 'name' => 'test', 'filial' => array( 'test1', 'test2', 'test3', ) ), ); foreach ($_SESSION['explode'] as $explode) { $tr[] = '<td>' . $explode['name'] . '</td><td>' . implode('</td><td>', $explode['filial']) . '</td>'; } 
  • Please clarify because you wrote the wrong decision, - Mr. Nomov
  • Simply explaining, even by your example, it is necessary not to test, but specifically for example test1 or test2 or test3 of the internal filial array - Mr. Nomov
  • Well, in my example, he will print test and test1, tes2, test3. I may have misunderstood something, write at least what html should end up at the output - Daniel-664
  • So again, there is in the array of the city: City1, City2, City3 and so on. in the foreach cycle, I bring out these same cities here everything is OK, but the problem appears when you need to display the final city, i.e. to summarize which cities were derived So it means once again what should be at the conclusion We derive cities from the array: City1 City1 then essentially goes City2 BUT before City2, we output one value City1. Here I will add in HTML format: <td> City 1 </ td> <td> City 1 </ td> <td> City 1 </ td> <td> City 1 </ td> </ br> <td> Total : City 1 </ td> and so on ... <td> City 2 </ td> Total City2 - Mr. Nomov
  • Ok, then I'll ask again. Why do you need to display the same city 4 times? (I’m <td> Город 1</td> <td> Город 1 </td> <td> Город 1</td> <td> Город 1 </td> about this <td> Город 1</td> <td> Город 1 </td> <td> Город 1</td> <td> Город 1 </td> ) And why do we need to divide the table cells through </br> (which is also <br/> ) when can you make 2 <tr> lines? - Daniel-664