<?php
$arr = [
"title" =>
[
0 => "title1",
1 => "title2",
2 => "title3",
],
"icon-class" =>
[
0 => "class1",
1 => "class2",
2 => "class3",
],
"text" =>
[
0 => "text1",
1 => "text2",
2 => "text3",
],
"link-text" =>
[
0 => "link-text1",
1 => "link-text2",
2 => "link-text3",
],
"link" =>
[
0 => "link-text1",
1 => "link-text2",
2 => "link-text3",
],
];
// fetching keys
$keys = array_keys($arr);
// transposing array with removing string keys to integer
$temp = array_map(null, ...array_values($arr));
// combining fetched keys and values by transpose
$temp = array_map(function ($item) use ($keys) {return array_combine($keys, $item);}, $temp);
?>
<ul>
<?php foreach($temp as $v): ?>
<li>
<h3 class="<?php echo $v['icon-class'] ?>"><?php echo $v['title'];?></h3>
<p><?php echo $v['text'];?></p>
<a href="<?php echo $v['link']; ?>"><?php echo $v['link-text']?></a>
</li>
<?php endforeach; ?>
</ul>
- Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- <ul>
<li>
<h3 class="class1">title1</h3>
<p>text1</p>
<a href="link-text1">link-text1</a>
</li>
<li>
<h3 class="class2">title2</h3>
<p>text2</p>
<a href="link-text2">link-text2</a>
</li>
<li>
<h3 class="class3">title3</h3>
<p>text3</p>
<a href="link-text3">link-text3</a>
</li>
</ul>
preferences:
91.91 ms | 408 KiB | 5 Q