Answer the question
In order to leave comments, you need to log in
How to concatenate array rows?
The database contains entries in the style:
Array ( [id] => 1 [data] => 03.03.15 09:28:46 [latitude] => 49.23342514 [longitude] => 28.40869522 [ppm] => ppm= )
Array ( [id] => 2 [data] => 03.03.15 09:28:46 [latitude] => 49.23342514 [longitude] => 28.40869522 [ppm] => 701 )
Array ( [id] => 3 [data] => 03.03.15 09:28:47 [latitude] => 49.23335648 [longitude] => 28.40859604 [ppm] => ppm )
Array ( [id] => 4 [data] => 03.03.15 09:28:47 [latitude] => 49.23335648 [longitude] => 28.40859604 [ppm] => =679 )
Array ( [id] => 5 [data] => 03.03.15 09:28:48 [latitude] => 49.23325729 [longitude] => 28.40863609 [ppm] => pp )
Array ( [id] => 6 [data] => 03.03.15 09:28:48 [latitude] => 49.23325729 [longitude] => 28.40863609 [ppm] => m=65 )
Array ( [id] => 7 [data] => 03.03.15 09:28:48 [latitude] => 49.23325729 [longitude] => 28.40863609 [ppm] => 6 )
Array ( [id] => 1 [data] => 03.03.15 09:28:46 [latitude] => 49.23342514 [longitude] => 28.40869522 [ppm] => ppm=701 )
Array ( [id] => 3 [data] => 03.03.15 09:28:47 [latitude] => 49.23335648 [longitude] => 28.40859604 [ppm] => ppm=679)
Array ( [id] => 5 [data] => 03.03.15 09:28:48 [latitude] => 49.23325729 [longitude] => 28.40863609 [ppm] => ppm=656 )
Answer the question
In order to leave comments, you need to log in
And it's even easier - to store classes at once or filter at the sampling stage.
<?php
class GeoPosition {
private $data;
public function __construct(array $data)
{
$this->data = $data;
}
public function getData()
{
return $this->data;
}
public function __toString()
{
return $data['data'];
}
}
/** @var array[] $dbResponse */
$normalizedData = array_map(function (array $geoPosition) {
return new GeoPosition($geoPosition);
}, $dbResponse);
$filteredData = array_unique($normalizedData, SORT_STRING);
$denormalized = array_map(function (GeoPosition $geoPosition) {
return $geoPosition->getData();
}, $filteredData);
if(($length = count($arr)) > 1)
for($i = 1, $row = $arr[0]; $i < $length; $i++) {
if($row['data'] === $arr[$i]['data'])
$arr[$i]['ppm'] = $row['ppm'] . $arr[$i]['ppm'];
else
$row = $arr[$i];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question