$data = 's:298:"a:3:{i:0;a:3:{s:4:"Year";s:4:"2010";s:5:"Movie";s:18:"Mission Impossible";s:4:"Role";s:5:"Actor";}i:1;a:3:{s:4:"Year";s:4:"2011";s:5:"Movie";s:20:"Mission Impossible 2";s:4:"Role";s:10:"Lead Actor";}i:2;a:3:{s:4:"Year";s:4:"2012";s:5:"Movie";s:20:"Mission Impossible 3";s:4:"Role";s:8:"Director";}}";';
// first remove the string declaration at the start, if you don't do this, unserialize() will treat most of the data as a string and won't convert it to an array
$data = substr($data, strpos($data, '"')+1);
// now just unserialize into an array so it can be looped through with foreach() etc
$arr = unserialize($data);
print_r($arr);
Выходы
Array
(
[0] => Array
(
[Year] => 2010
[Movie] => Mission Impossible
[Role] => Actor
)
[1] => Array
(
[Year] => 2011
[Movie] => Mission Impossible 2
[Role] => Lead Actor
)
[2] => Array
(
[Year] => 2012
[Movie] => Mission Impossible 3
[Role] => Director
)
)
Чтобы перебрать массив, вы можете использовать foreach
:
<?php
$html = '<table>';
// table headings
$html .= '<tr><th>Year</th><th>Movie</th><th>Role</th></tr>';
foreach($arr as $item)
{
$html .= '<tr>';
$html .= '<td>' . $item['Year'] . '</td>';
$html .= '<td>' . $item['Movie'] . '</td>';
$html .= '<td>' . $item['Role'] . '</td>';
$html .= '</tr>';
}
$html .= '</table>';
echo $html; // output the HTML table
?>