Home ›
Removing the current node's ID from an array of node IDsRemoving the current node's ID from an array of node IDs
Searched words:
cut excise delete get rid of present NID
Didn't work:
<?php
// Remove the current node ID, if present. This looks crazy but it's fast,
// see http://lixlpixel.org/php-benchmarks/remove-array-items-by-value
if ($nids) {
$nids = explode(',', str_replace($current_nid . ',', '', join(',', $nids)));
}
?>
Worked:
<?php
// Remove the current nid if present.
if ($nids) {
$key = array_search($current_nid, $nids);
if ($key !== FALSE) {
unset($nids[$key]);
}
}
?>
More like this
- Remove a trailing slash (if any) from a string with PHP
- Get a node's taxonomy terms that are in a given vocabulary
- Disabling or moving node/add/[content-type] links from beneath "Add content" in the navigation menu also removes them from the Add content page (node/add)
- Exclude the current node from also showing up in a block View
- Declaring functions in node content results in cannot redeclare fatal error in eval()'d code


Comments
Post new comment