I have an array in PHP like this:
$link_array = [
"Our_dogs" => "ourdogs.php",
"About_us" => "aboutus.php",
"Puppies" => "puppies.php",
"Contact" => "contact.php",
"Login" => "login.php",
"Guestbook" => "guestbook.php"
];
I want to pass this array to javascript and then print it on my page, but if Im on, for example, the page for Our dogs, I dont want that link to show. Is that possible?
I have tried this:
foreach($link_array as $key=>$value){
if(($key == "Our_dogs") && ($value == "ourdogs.php")){
$_SESSION['Our dogs'] = $value;
break;
}
$responseText['Our_dogs'] = $_SESSION['Our_dogs'];
echo json_encode($responseText);
And this for JS:
var response = JSON.parse(this.responseText);
var li = document.createElement('li');
console.log(response.Our_dogs);
li.innerHTML = '<a href=\"' + response.Our_dogs + '\">OUR DOGS</a>';
byId("nav").appendChild(li);
but Im new to this and not sure how to do this. How can I do this in a correct way and is it possible to print only the links to the other pages (not the page showing)?