/** * Checks recursively if a value exists in an array * * @param mixed $needle The searched value. * @param array $haystack The array. * @param bool $strict If true also check value types * * @return bool true if needle is found in the array, false otherwise. */ function in_array_recursive($needle, $haystack, $strict = false) { if (in_array($needle, $haystack, $strict)) { return true; } foreach ($haystack as $v) { if (is_array($v) && in_array_recursive($needle, $v, $strict)) { return true; } } return false; }
/** * @dataProvider provide_in_array_recursive * @covers ::in_array_recursive * @param $needle * @param $haystack * @param $insensitive * @param $expected */ public function test_in_array_recursive($needle, $haystack, $insensitive, $expected) { $this->assertEquals($expected, in_array_recursive($needle, $haystack, $insensitive)); }
function in_array_recursive($value, $array) { foreach ($array as $item) { if (!is_array($item)) { if ($item == $value) { return true; } else { continue; } } if (in_array($value, $item)) { return true; } else { if (in_array_recursive($value, $item)) { return true; } } } return false; }
</a> (#<?php print $d->p_num; ?> - <?php print $d->pos_name; ?> )</li> <li>Died: <?php print date("d.m.25y", $d->mdate); ?> </li> <?php //If the player has won an eagle award, let everyone know //first we check something is in the eagles array if ($eagles_exist) { if (in_array_recursive($d->p_id, $eagles)) { print "\t\t\t\t<li class=\"gyhighlight\">Eagle Award Winning Death!</li>\n"; } } ?> </ul> </div><!-- end of .gyplayer --> <?php } //end of foreach $dead print "\t</div><!-- end of .gycontainer -->\n"; } else { print "\t<p>Nobody has died!</p>\n"; } //Did You Know Display Code if (function_exists(bblm_display_dyk)) {
/** * Recursive in_array function * * @param string $needle What to search for * @param array $haystack What to search in * @param bool $insensitive Whether or not to do a case-insensitive search * @return bool True if $needle is found in $haystack * @link http://us3.php.net/in_array */ function in_array_recursive($needle, $haystack, $insensitive = false) { $fnc = 'in_array'; if ($insensitive) { $fnc = 'iin_array'; } if ($fnc($needle, $haystack)) { return true; } foreach ($haystack as $val) { if (is_array($val)) { return in_array_recursive($needle, $val); } } return false; }
if (ip_in_network($qname_ip, $prefix) || $qname == $suffix['suffix']) { $result = array('result' => array(array('qtype' => 'SOA', 'qname' => $qname, 'content' => implode(" ", $soa), 'ttl' => $soa[6]))); } break; case 'NS': break; default: // Convert to IP and confirm it's in this prefix if (ip_in_network($qname_ip, $prefix)) { $result = array('result' => array(array('qtype' => 'A', 'qname' => $qname, 'content' => $qname_ip, 'ttl' => $soa[6]))); } break; } } } } elseif (in_array_recursive($qname_parts[2], $suffix_ipv6)) { // Get IP from $qname_parts if possible if ($qname_parts[1]) { $qname_ip = str_replace('-', ':', $qname_parts[1]); } foreach ($suffix_ipv6 as $prefix => $suffix) { if ($suffix['suffix'] == $qname_parts[2]) { switch ($qtype) { case 'SOA': if (ip_in_network6($qname_ip, $prefix) || $qname == $suffix['suffix']) { $result = array('result' => array(array('qtype' => 'SOA', 'qname' => $qname, 'content' => implode(" ", $soa), 'ttl' => $soa[6]))); } break; case 'NS': break; default:
if (!is_null($talkpageobject)) { $talkpageobject = $site->initPage(null, $talkpageobject); } $out = "{{Blacklisted-links|1="; $out2 = ""; foreach ($page['urls'] as $l => $url) { $out2 .= "\n*{$url}"; $out2 .= "\n*:''Triggered by <code>{$page['rules'][$l]['rule']}</code> on the {$page['rules'][$l]['blacklist']} blacklist''"; } $out .= "{$out2}|bot=Cyberbot II|invisible=false}}\n"; $templates = $pageobject->get_templates(); $oldtext = $buffer = $pageobject->get_text(); if ($buffer == "" || is_null($buffer)) { continue; } if (in_array_recursive('Template:Blacklisted-links', $templates)) { preg_match('/\\{\\{Blacklisted\\-links\\|(1\\=)?(\\n)?((.(\\n)?)*?)\\|bot\\=Cyberbot II(\\|invisible=(.*?))?\\}\\}(\\n)?/i', $buffer, $template); $linkstrings = $template[3]; $template = $template[0]; if (trim($out2) == trim("\n" . $linkstrings)) { goto placenotice; } $out = str_replace(trim("\n" . $linkstrings), trim($out2), $template); $buffer = str_replace($template, $out, $buffer); if ($oldtext != $buffer) { $success = $pageobject->edit($buffer, "Updating {{[[Template:Blacklisted-links|Blacklisted-links]]}}.", true); } else { $success = false; } } else { preg_match('/^\\s*(?:((?:\\s*\\{\\{\\s*(?:about|correct title|dablink|distinguish|for|other\\s?(?:hurricaneuses|people|persons|places|uses(?:of)?)|redirect(?:-acronym)?|see\\s?(?:also|wiktionary)|selfref|the)\\d*\\s*(\\|(?:\\{\\{[^{}]*\\}\\}|[^{}])*)?\\}\\})+(?:\\s*\\n)?)\\s*)?/i', $buffer, $temp);