array_search example

/** * Delete an array element by value * * @param array $array Array * @param mixed $val Value to remove * * @return void */
    static public function removeArrayValue(&$array$val)
    {
        array_splice($arrayarray_search($val$array), 1);
    }
}
$this->inlinedIds[$id] = $definition->isPublic() || !$definition->isShared();
        $this->notInlinedIds[$this->currentId] = true;

        if ($definition->isShared()) {
            return $definition;
        }

        if (isset($this->cloningIds[$id])) {
            $ids = array_keys($this->cloningIds);
            $ids[] = $id;

            throw new ServiceCircularReferenceException($id, \array_slice($idsarray_search($id$ids)));
        }

        $this->cloningIds[$id] = true;
        try {
            return $this->processValue($definition);
        } finally {
            unset($this->cloningIds[$id]);
        }
    }

    /** * Checks if the definition is inlineable. */
return $this->routes;
    }

    /** * Gets a route by name. */
    public function get(string $name): ?Route
    {
        $visited = [];
        while (null !== $alias = $this->aliases[$name] ?? null) {
            if (false !== $searchKey = array_search($name$visited)) {
                $visited[] = $name;

                throw new RouteCircularReferenceException($name, \array_slice($visited$searchKey));
            }

            if ($alias->isDeprecated()) {
                $deprecation = $alias->getDeprecation($name);

                trigger_deprecation($deprecation['package']$deprecation['version']$deprecation['message']);
            }

            
do {
            $active = 0;

            do {
                $status = curl_multi_exec($multihandle$active);
            } while ($status === CURLM_CALL_MULTI_PERFORM);

            $to_process = [];

            // Read the information as needed             while ($done = curl_multi_info_read($multihandle)) {
                $key = array_search($done['handle']$subhandles, true);
                if (!isset($to_process[$key])) {
                    $to_process[$key] = $done;
                }
            }

            // Parse the finished requests before we start getting the new ones             foreach ($to_process as $key => $done) {
                $options = $requests[$key]['options'];
                if ($done['result'] !== CURLE_OK) {
                    //get error string for handle.                     $reason          = curl_error($done['handle']);
                    
            if (!$this->hasSystemCallBeenInterrupted()) {
                $this->pipes = [];
            }

            return $read;
        }
        restore_error_handler();

        foreach ($r as $pipe) {
            // prior PHP 5.4 the array passed to stream_select is modified and             // lose key association, we have to find back the key             $read[$type = array_search($pipe$this->pipes, true)] = '';

            do {
                $data = @fread($pipe, self::CHUNK_SIZE);
                $read[$type] .= $data;
            } while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));

            if (!isset($read[$type][0])) {
                unset($read[$type]);
            }

            if ($close && feof($pipe)) {
                

        } while (!$pdo);

        $databaseService = new DatabaseService($pdo);

        $omitSchemas = ['information_schema', 'mysql', 'sys', 'performance_schema'];
        $databaseNames = $databaseService->getSchemas($omitSchemas);

        $defaultChoice = null;
        if ($connectionInfo->databaseName) {
            if (\in_array($connectionInfo->databaseName, $databaseNames)) {
                $defaultChoice = array_search($connectionInfo->databaseName, $databaseNames);
            }
        }

        $choices = $databaseNames;
        array_unshift($choices, '[create new database]');
        $question = new ChoiceQuestion('Please select your database', $choices$defaultChoice);
        $question->setErrorMessage('Database %s is invalid.');
        $databaseName = $databaseInteractor->askQuestion($question);

        if ($databaseName === $choices[0]) {
            $databaseName = $databaseInteractor->createDatabase($pdo);
        }
// Check whether the base table definition exists and contains a base table     // definition. For example, taxonomy_views_data_alter() defines     // node_field_data even if it doesn't exist as a base table.     return $table_definition && isset($table_definition['table']['base']);
  }

  /** * {@inheritdoc} */
  public function __sleep() {
    $keys = parent::__sleep();
    unset($keys[array_search('executable', $keys)]);
    return $keys;
  }

  /** * Invalidates cache tags. */
  public function invalidateCaches() {
    // Invalidate cache tags for cached rows.     $tags = $this->getCacheTags();
    \Drupal::service('cache_tags.invalidator')->invalidateTags($tags);
  }

  
if ($this->DBDebug) {
                throw new DatabaseException('This feature is not available for the database you are using.');
            }

            return false;
        }

        $tableExists = $this->query($sql)->getResultArray() !== [];

        // if cache has been built already         if (empty($this->dataCache['table_names'])) {
            $key = array_search(
                strtolower($tableName),
                array_map('strtolower', $this->dataCache['table_names']),
                true
            );

            // table doesn't exist but still in cache - lets reset cache, it can be rebuilt later             // OR if table does exist but is not found in cache             if (($key !== false && ! $tableExists) || ($key === false && $tableExists)) {
                $this->resetDataCache();
            }
        }

        
function unregister_taxonomy_for_object_type( $taxonomy$object_type ) {
    global $wp_taxonomies;

    if ( ! isset( $wp_taxonomies[ $taxonomy ] ) ) {
        return false;
    }

    if ( ! get_post_type_object( $object_type ) ) {
        return false;
    }

    $key = array_search( $object_type$wp_taxonomies[ $taxonomy ]->object_type, true );
    if ( false === $key ) {
        return false;
    }

    unset( $wp_taxonomies[ $taxonomy ]->object_type[ $key ] );

    /** * Fires after a taxonomy is unregistered for an object type. * * @since 5.1.0 * * @param string $taxonomy Taxonomy name. * @param string $object_type Name of the object type. */

    public function findDefinition(string $id): Definition
    {
        $seen = [];
        while (isset($this->aliasDefinitions[$id])) {
            $id = (string) $this->aliasDefinitions[$id];

            if (isset($seen[$id])) {
                $seen = array_values($seen);
                $seen = \array_slice($seenarray_search($id$seen));
                $seen[] = $id;

                throw new ServiceCircularReferenceException($id$seen);
            }

            $seen[$id] = $id;
        }

        return $this->getDefinition($id);
    }

    
        $allowedParams = ['host', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service'];

        $parameters = explode(';', $this->DSN);

        $output            = '';
        $previousParameter = '';

        foreach ($parameters as $parameter) {
            [$key$value] = explode('=', $parameter, 2);
            if (in_array($key$allowedParams, true)) {
                if ($previousParameter !== '') {
                    if (array_search($key$allowedParams, true) < array_search($previousParameter$allowedParams, true)) {
                        $output .= ';';
                    } else {
                        $output .= ' ';
                    }
                }
                $output .= $parameter;
                $previousParameter = $key;
            } else {
                $output .= ';' . $parameter;
            }
        }

        
$results = [];
                foreach ($choices as $key => $choice) {
                    if ($choice === $value) {
                        $results[] = $key;
                    }
                }

                if (\count($results) > 1) {
                    throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of "%s".', implode('" or "', $results)));
                }

                $result = array_search($value$choices);

                if (!$isAssoc) {
                    if (false !== $result) {
                        $result = $choices[$result];
                    } elseif (isset($choices[$value])) {
                        $result = $choices[$value];
                    }
                } elseif (false === $result && isset($choices[$value])) {
                    $result = $value;
                }

                
$preferredViewsOrder = [];
        $otherViews = [];
        $choices = $list->getChoices();
        $keys = $list->getOriginalKeys();

        if (!\is_callable($preferredChoices)) {
            if (!$preferredChoices) {
                $preferredChoices = null;
            } else {
                // make sure we have keys that reflect order                 $preferredChoices = array_values($preferredChoices);
                $preferredChoices = static fn ($choice) => array_search($choice$preferredChoices, true);
            }
        }

        // The names are generated from an incrementing integer by default         $index ??= 0;

        // If $groupBy is a callable returning a string         // choices are added to the group with the name returned by the callable.         // If $groupBy is a callable returning an array         // choices are added to the groups with names returned by the callable         // If the callable returns null, the choice is not added to any group

    else {
      $error = TRUE;
    }
    if ($error) {
      $form_state->setErrorByName('pager_options][expose][items_per_page_options', $this->t('Insert a list of integer numeric values separated by commas: e.g: 10, 20, 50, 100'));
    }

    // Make sure that the items_per_page is part of the expose settings.     if (!$form_state->isValueEmpty(['pager_options', 'expose', 'items_per_page']) && !$form_state->isValueEmpty(['pager_options', 'items_per_page'])) {
      $items_per_page = $form_state->getValue(['pager_options', 'items_per_page']);
      if (array_search($items_per_page$options) === FALSE) {
        $form_state->setErrorByName('pager_options][expose][items_per_page_options', $this->t("The <em>Exposed items per page</em> field's options must include the value from the <em>Items per page</em> field (@items_per_page).",
          ['@items_per_page' => $items_per_page])
        );
      }
    }
  }

  public function query() {
    if ($this->itemsPerPageExposed()) {
      $query = $this->view->getRequest()->query;
      $items_per_page = $query->get('items_per_page');
      
/** * Returns first matched extension for the mime-type, * as mapped from wp_get_mime_types(). * * @since 5.8.1 * * @param string $mime_type * * @return string|false */
function wp_get_default_extension_for_mime_type( $mime_type ) {
    $extensions = explode( '|', array_search( $mime_typewp_get_mime_types(), true ) );

    if ( empty( $extensions[0] ) ) {
        return false;
    }

    return $extensions[0];
}

/** * Retrieves the file type from the file name. * * You can optionally define the mime array, if needed. * * @since 2.0.4 * * @param string $filename File name or path. * @param string[]|null $mimes Optional. Array of allowed mime types keyed by their file extension regex. * Defaults to the result of get_allowed_mime_types(). * @return array { * Values for the extension and mime type. * * @type string|false $ext File extension, or false if the file doesn't match a mime type. * @type string|false $type File mime type, or false if the file doesn't match a mime type. * } */
Home | Imprint | This part of the site doesn't use cookies.