Hope someone can help with this
I'm using this to grab the first part of my URL
$page_url = perch_page_url(['include-domain' => false,], true); //
Output the URL of the current page, minus https
$url_parts = explode("/", $page_url); // Split a string by a string
I'm using this technique to grab the first and second nodes of the URL
$first_node = $url_parts[1]; // First part of string
$second_node = $url_parts[2]; // Second part of string
On my homepage, there isn't a second node, so I get an undefined offset
message.
Is there a way to check if the $second_node
exists?
I've tried using
if (isset($second_node)) {
echo "$second_node is set so I will print.";
}
and
if (!empty($second_node)) {
echo '$second_node is either 0, empty, or not set at all';
}
Both if
statements only echo after the $second_node has been set? So I still get the error message.