Example as $Example ) Thank. +5 ...">

The 'as' operator in PHP

In PHP, what does the "how" operator do? For instance,

foreach ( $this->Example as $Example )

Thank.

+5
source share
7 answers

Take an example:

foreach ($array as $value) {}

It means

for each item (of $array) defined as $value...

In other words, this means that the elements of the array will be extracted inside the loop as $value. Note that you can also specify this syntax:

foreach ($array as $key => $value) {}

In both cases, vars $keyand $valuewill exist inside foreachand will correspond to the "current" element of the array.

+12
source

foreach ( /), .

+2

foreach $Example .

+2

http://php.net/manual/en/control-structures.foreach.php

foreach (array_expression as $value)
    statement

, array_expression.

$value, ( ).

+2
0

foreach . foreach ( $this->Example). , , as ( , $Example) ​​ .

0

. as. :

foreach ($dictionary as $key => $value) {}

:

<?php
namespace foo;
use Full\Class\Path as MyAlias;
new MyAlias();

, . AVeryLongClassNameThatRendersYourCodeUnreadable .

0

All Articles