CKTIS / PHP
extract()
Import valid keys as local variable names and return the number imported.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
extract(array &$array, int $flags = EXTR_OVERWRITE, string $prefix = ""): intImport valid keys as local variable names and return the number imported. EXTR_OVERWRITE replaces an existing variable by default. EXTR_SKIP preserves it. Restrict this operation to a known mapping because keys control local names.
Signature
extract(array &$array, int $flags = EXTR_OVERWRITE, string $prefix = ""): int
Example output
[1,"old",4]
Examples
<?php
$label="old"; $fields=["label"=>"new","units"=>4,"bad-key"=>8];
$count=extract($fields, EXTR_SKIP);
echo json_encode([$count,$label,$units]);
Result
[1,"old",4]