“Extracto en PHP” Código de respuesta

STPO en PHP


<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}
?>

Kaotik

Valor de extracto de matriz PHP


<?php
$array = array("size" => "XL", "color" => "gold");
print_r(array_values($array));
?>

Matteoweb

Extracto en PHP

$arr = array('mango'=>'My favourite fruit','apple'=>'It is good for health','banana'=>'it is good for bones'); 

// it will convert array to variable 

extract($arr); 

echo $mango."</br>"; 

echo $apple."</br>"; 

echo $banana; 
kinjal suryavanshi

Extracto en PHP útil

I find that it is only bad practice in that it can lead to a number of variables
which future maintainers (or yourself in a few weeks) have no idea where 
they are coming from. 

Consider this scenario:

extract($someArray); // could be $_POST or anything

/* snip a dozen or more lines */

echo $someVariable;
Where did $someVariable come from? How can anyone tell?

I dont see the problem in accessing the variables from within the array they 
started in, so you would really need to present a good case for using extract() 
for me to think it is worth it. If you are really concerned about typing out 
some extra characters then just do this:

$a = $someLongNameOfTheVariableArrayIDidntWantToType;

$a['myVariable'];

I think the comments here on the security aspects of it are overblown somewhat.
The function can take a second parameter that actually gives you fairly good 
control over the 
newly created variables, including not overwriting any existing variables
(EXTR_SKIP), ONLY overwriting existing variables (so you can create a whitelist)
(EXTR_IF_EXISTS), or adding prefixes to the variables (EXTR_PREFIX_ALL).
Wide-eyed Wolf

Respuestas similares a “Extracto en PHP”

Preguntas similares a “Extracto en PHP”

Más respuestas relacionadas con “Extracto en PHP” en PHP

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código