PHP -zelfstudie

PHP HOME PHP-intro PHP-installatie PHP-syntaxis PHP-opmerkingen PHP-variabelen PHP-echo / afdrukken PHP-gegevenstypen PHP-strings PHP-nummers PHP-wiskunde PHP-constanten PHP-operators PHP Als...Anders...Anders PHP-switch PHP-loops PHP-functies PHP-arrays PHP Superglobals PHP RegEx

PHP- formulieren

PHP-formulierverwerking PHP-formuliervalidatie PHP-formulier vereist URL/e-mail van PHP-formulier PHP-formulier voltooid

PHP Geavanceerd

PHP-datum en tijd PHP opnemen PHP-bestandsverwerking PHP-bestand openen/lezen PHP-bestand maken/schrijven PHP-bestand uploaden PHP-cookies PHP-sessies PHP-filters PHP-filters geavanceerd PHP-callback-functies PHP JSON PHP-uitzonderingen

PHP OOP

PHP Wat is OOP PHP-klassen/objecten PHP-constructor PHP-vernietiger PHP-toegangsmodificaties PHP-overerving PHP-constanten PHP abstracte lessen PHP-interfaces PHP-kenmerken PHP statische methoden Statische eigenschappen van PHP PHP-naamruimten PHP-iterables

MySQL- database

MySQL-database MySQL Connect MySQL DB maken MySQL-tabel maken MySQL Gegevens invoegen MySQL Laatste ID ophalen MySQL Meerdere invoegen MySQL voorbereid MySQL Gegevens selecteren MySQL Waar MySQL Bestel op MySQL Gegevens verwijderen MySQL-updategegevens MySQL-limietgegevens

PHP XML

PHP XML-parsers PHP SimpleXML-parser PHP SimpleXML - Get PHP XML Expat PHP XML DOM

PHP - AJAX

Ajax-intro AJAX PHP AJAX-database AJAX XML Live zoeken in Ajax Ajax-peiling

PHP- voorbeelden

PHP-voorbeelden PHP-compiler PHP-quiz PHP-oefeningen PHP-certificaat

PHP- referentie

PHP-overzicht PHP-array PHP-agenda PHP-datum PHP-map PHP-fout PHP-uitzondering PHP-bestandssysteem PHP-filter PHP FTP PHP JSON PHP-sleutelwoorden PHP Libxml PHP-e-mail PHP-wiskunde PHP Diversen PHP MySQLi PHP-netwerk PHP-uitvoercontrole PHP RegEx PHP SimpleXML PHP-stream PHP-string Beheer van PHP-variabelen PHP XML-parser PHP-zip PHP-tijdzones

PHP extract() Functie

❮ Referentie voor PHP-array

Voorbeeld

Ken de waarden "Kat", "Hond" en "Paard" toe aan de variabelen $a, $b en $c:

<?php
$a = "Original";
$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
extract($my_array);
echo "\$a = $a; \$b = $b; \$c = $c";
?>

Definitie en gebruik

De functie extract() importeert variabelen in de lokale symbooltabel vanuit een array.

Deze functie gebruikt array-sleutels als variabelenamen en waarden als variabelewaarden. Voor elk element wordt een variabele gemaakt in de huidige symbolentabel.

Deze functie retourneert het aantal variabelen dat bij succes is geëxtraheerd.


Syntaxis

extract(array, extract_rules, prefix)

Parameterwaarden

Parameter Description
array Required. Specifies the array to use
extract_rules Optional. The extract() function checks for invalid variable names and collisions with existing variable names. This parameter specifies how invalid and colliding names are treated.

Possible values:

  • EXTR_OVERWRITE - Default. On collision, the existing variable is overwritten
  • EXTR_SKIP - On collision, the existing variable is not overwritten
  • EXTR_PREFIX_SAME - On collision, the variable name will be given a prefix
  • EXTR_PREFIX_ALL - All variable names will be given a prefix
  • EXTR_PREFIX_INVALID - Only invalid or numeric variable names will be given a prefix
  • EXTR_IF_EXISTS - Only overwrite existing variables in the current symbol table, otherwise do nothing
  • EXTR_PREFIX_IF_EXISTS - Only add prefix to variables if the same variable exists in the current symbol table
  • EXTR_REFS - Extracts variables as references. The imported variables are still referencing the values of the array parameter
prefix Optional. If EXTR_PREFIX_SAME, EXTR_PREFIX_ALL, EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS are used in the extract_rules parameter, a specified prefix is required.

This parameter specifies the prefix. The prefix is automatically separated from the array key by an underscore character.


Technische details

Winstwaarde: Retourneert het aantal variabelen dat bij succes is geëxtraheerd
PHP-versie: 4+
PHP-wijzigingslogboek: De extract_rules- waarde EXTR_REFS is toegevoegd in PHP 4.3.

De extract_rules- waarden EXTR_IF_EXISTS en EXTR_PREFIX_IF_EXISTS zijn toegevoegd in PHP 4.2.

Vanaf PHP 4.0.5 retourneert deze functie nu het aantal geëxtraheerde variabelen.

De extract_rules- waarde EXTR_PREFIX_INVALID is toegevoegd in PHP 4.0.5.

Vanaf PHP 4.0.5 bevat de extract_rules- waarde EXTR_PREFIX_ALL nu ook numerieke variabelen.

Meer voorbeelden

Voorbeeld

Alle parameters gebruiken:

<?php
$a = "Original";
$my_array = array("a" => "Cat", "b" => "Dog", "c" => "Horse");

extract($my_array, EXTR_PREFIX_SAME, "dup");

echo "\$a = $a; \$b = $b; \$c = $c; \$dup_a = $dup_a";
?>

❮ Referentie voor PHP-array