I have an array PHPin which I have some related information to echo like this.
<?php
$options = array(
array("name" => "Title",
"desc" => "Description",
"type" => '_one',
"tab-name" => "Tab 1"
),
array("name" => "Title2",
"desc" => "Description2",
"type" => '_two',
"tab-name" => "Tab 2"
),
array("name" => "Title3",
"desc" => "Description3",
"type" => '_three',
"tab-name" => "Tab 3"
)
)
?>
I created a function for the echo name, desc and works great
There he is:
<?php
function create_heading($value) {
echo '<h2>'.$value['name'].'</h2>';
}
function create_description($value){
echo '<p>'.$value['desc'].'</p>'
}
function wrapper1($value) {
echo '<h1>This is the wrapper 1</h1>'
create_heading($value);
create_description($value);
}
function wrapper2($value) {
echo '<h1>This is the wrapper 2</h1>'
create_heading($value);
create_description($value);
}
function wrapper2($value) {
echo '<h1>This is the wrapper 3</h1>'
create_heading($value);
create_description($value);
}
function render_things($options) {
foreach ($options as $value) {
switch($value['type']) {
case "one":
wrapper1($value);
break;
case "two":
wrapper2($value);
case "three":
wrapper3($value);
}
}
}
render_things();
?>
What is the problem:
The problem is how can I dynamically display these values inside the tab according to the tab name in the array, because I gave the value of the second array in the tab name, these are two, so it should print on the second tab if I change it to one or three, it should print values up to one or three respectively.
Hope you guys understand.
body {font-family: "Lato", sans-serif;}
div.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
div.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
div.tab button:hover {
background-color: #ddd;
}
div.tab button.active {
background-color: #ccc;
}
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'tab1')" id="defaultOpen">tab 1</button>
<button class="tablinks" onclick="openCity(event, 'tab2')">tab 2</button>
<button class="tablinks" onclick="openCity(event, 'tab3')">Tab 3</button>
</div>
<div id="tab1" class="tabcontent">
<h1>This is tab 1</h1>
</div>
<div id="tab2" class="tabcontent">
<h1>This is tab 2</h1>
</div>
<div id="tab3" class="tabcontent">
<h1>This is tab 3</h1>
</div>
<script>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
document.getElementById("defaultOpen").click();
</script>
Run codeHide result: js , , , js, PHP.