Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try the below code</p> <pre class="lang-php prettyprint-override"><code>$prevIssue_arr = $comic-&gt;xpath('preceding-sibling::*[1]'); $prevIssue = (isset($prevIssue_arr[0])) ? $prevIssue_arr[0]-&gt;mainsection-&gt;series-&gt;displayname : ''; $nextIssue_arr = $comic-&gt;xpath('following-sibling::*[1]'); $nextIssue = (isset($nextIssue_arr[0])) ? $nextIssue_arr[0]-&gt;mainsection-&gt;series-&gt;displayname : ''; echo ... </code></pre> <p>[Edited] </p> <p>The others have already explained why the code did not work </p> <p>One is that the <code>xpath()</code> method returns an array of SimpleXMLElement objects. If no matching node is found, an empty array is returned. </p> <p>The other is that without the predicate <code>[1]</code> or <code>[position()=1]</code> in the location path, all the preceding or succeeding <code>comic</code> nodes would be returned. </p> <p>Alternatively you can use the location path <code>'following-sibling::comic[1]/mainsection/series'</code> to get just the required <code>series</code> node from the immediate succeeding sibling. If there were multiple <code>series</code> nodes, the position would have to be given or all of them would be returned. </p> <p>So using this location path </p> <pre><code>$prevIssue_arr = $comic-&gt;xpath('preceding-sibling::comic[1]/mainsection/series'); $prevIssue = (isset($prevIssue_arr[0])) ? $prevIssue_arr[0]-&gt;displayname : ''; $nextIssue_arr = $comic-&gt;xpath('following-sibling::comic[1]/mainsection/series'); $nextIssue = (isset($nextIssue_arr[0])) ? $nextIssue_arr[0]-&gt;displayname : ''; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload