7
In Python we can unstructure a list like this:
lista = [ "Maça", "Pera" ]
maca, pera = lista
print(maca, pera)
the exit will be:
Maça Pera
I know that in PHP it is possible to get the result using the function list
$lista = [ "Maça", "Pera" ];
list($maca, $pera) = $lista;
echo "{$maca} {$pera}";
but I would like to know if it is possible to obtain the result using the same or similar Python notation?
I think the closest is to using the
list
, but you can use[$maca, $pera] = $lista
, has the same behavior aslist($maca, $pera) = $lista
, but omits thelist
.– Inkeliz
@Inkeliz I’m using the version 7.0.1 and I’m making the mistake:
<b>Parse error</b>: syntax error, unexpected '=' in <b>[...][...]</b>
– NoobSaibot
This is possible in PHP 7.1+.
– Inkeliz