<?php
$data = [
[
"name" => "Москва",
"address" => "Тверская ул., 10, Москва",
"zip" => 117334
],
[
"name" => "Москва",
"address" => "Тверская ул., 10, Москва",
"zip" => 117334
],
[
"name" => "Москва",
"address" => "Тверская ул., 10, Москва",
"zip" => 117334
],
[
"name" => "Санкт-Петербург",
"address" => "Невский пр., 14, Санкт-Петербург",
"zip" => 191186
],
[
"name" => "Санкт-Петербург",
"address" => "Невский пр., 14, Санкт-Петербург",
"zip" => 191186
],
[
"name" => "Санкт-Петербург",
"address" => "Невский пр., 14, Санкт-Петербург",
"zip" => 191186
],
[
"name" => "Нижний Новгород",
"address" => "Авиаторская ул., 12, Нижний Новгород, Нижегородская обл.",
"zip" => 603034
],
[
"name" => "Нижний Новгород",
"address" => "Авиаторская ул., 12, Нижний Новгород, Нижегородская обл.",
"zip" => 603034
],
[
"name" => "Нижний Новгород",
"address" => "Авиаторская ул., 12, Нижний Новгород, Нижегородская обл.",
"zip" => 603034
]
];
$new_data = [];
foreach ($data as $row) {
if (!array_key_exists($row['name'], $new_data)) {
$new_data[$row['name']] = [];
}
$new_data[$row['name']][] = $row;
}
echo '<pre>';
print_r($new_data);
echo '</pre>';
$countries = [
'Africa' => [ "Mammuthus columbi",
"African buffalo",
"Bongo",
"Giraffe",
"Zebra"],
'Australia' => [ "Australian echidna",
"Asian buffalo",
"Camel",
"Dingo",
"Kangaroo"],
];
foreach ($countries as $country => $cities) {
echo '<h2>'.$country.'</h2><br/>'.implode(',<br/>', $cities).'.<br/>';
}
$result = mysqli_query($dbc, "SELECT * FROM `table_products`");
if (mysqli_num_rows($result)>0) {
$row = mysqli_fetch_array($result);
do
{
echo '
<form action="" method="post" >
<div class="producs col-md-4">
<div class="product">
<img src="'.$row["images"].'" width="100%" alt="">
<a href="veiw.php?id='.$row["kod_product"].'">'.$row["name_product"].'</a>
<p>Цена: '.$row["price_roz"].'</p>
<a class="more" href="veiw.php?id='.$row["kod_product"].'">Подробнее</a>
</div>
</div>
</form>
';
}
while ($row = mysqli_fetch_array($result)) ;
$it = 1;
foreach ($results as $result) {
$active_sheet2->setCellValue('A'.$it, $result->yellowline1);
$active_sheet2->setCellValue('B'.$it, $result->yellowline2);
$active_sheet2->setCellValue('C'.$it, $result->yellowline3);
$active_sheet2->setCellValue('D'.$it, $result->yellowline4);
$it++;
}
$data = array(
0 => array(
'id' => 2,
'pagetitle' => 'Главная',
'parent' => 0
),
1 => array(
'id' => 3,
'pagetitle' => 'Категория',
'parent' => 2
),
2 => array(
'id' => 100,
'pagetitle' => 'Подкатегори 100',
'parent' => 5
),
3 => array(
'id' => 5,
'pagetitle' => 'Подкатегория 5 ',
'parent' => 2
)
);
$categories_array = array();
foreach ($data as $category) {
if (!in_array($category['id'], $categories_array)) {
$categories_array[$category['id']] = array();
$categories_array[$category['id']]['pagetitle'] = $category['pagetitle'];
$categories_array[$category['id']]['parent'] = $category['parent'];
}
}
echo '<pre>';
print_r($categories_array);
echo '</pre>';