Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #12093 > unrolled thread

foreach as list

Started byrichard <noreply@example.com>
First post2013-12-03 10:10 -0500
Last post2013-12-04 00:48 +0000
Articles 8 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  foreach as list richard <noreply@example.com> - 2013-12-03 10:10 -0500
    Re: foreach as list Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-03 16:18 +0100
    Re: foreach as list richard <noreply@example.com> - 2013-12-03 10:16 -0500
    Re: foreach as list Richard Yates <richard@yatesguitar.com> - 2013-12-03 11:30 -0800
      Re: foreach as list Jerry Stuckle <jstucklex@attglobal.net> - 2013-12-03 14:40 -0500
        Re: foreach as list Scott Johnson <noonehome@chalupasworld.com> - 2013-12-03 13:23 -0800
          Re: foreach as list Jerry Stuckle <jstucklex@attglobal.net> - 2013-12-03 20:30 -0500
    Re: foreach as list Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-12-04 00:48 +0000

#12093 — foreach as list

Fromrichard <noreply@example.com>
Date2013-12-03 10:10 -0500
Subjectforeach as list
Message-ID<1lb2ueqjc0qju.xhszpol7p3t4.dlg@40tude.net>
foreach ($six0 as list($a,$b)){
  echo $a"\n";
  echo $b"\n";
  
}

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

Used as shown in the example, I get this:
Parse error: syntax error, unexpected T_LIST, expecting '&' or T_STRING or
T_VARIABLE or '$

Their example:

<?php
$array = [
    [1, 2],
    [3, 4],
];

foreach ($array as list($a)) {
    // Note that there is no $b here.
    echo "$a\n";
}
?>

The above example will output:

1
3

[toc] | [next] | [standalone]


#12094

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2013-12-03 16:18 +0100
Message-ID<529df63a$0$6636$9b4e6d93@newsspool2.arcor-online.net>
In reply to#12093
richard wrote:

> foreach ($six0 as list($a,$b)){
>   echo $a"\n";
>   echo $b"\n";
>   
> }
> 
> http://us1.php.net/manual/en/control-structures.foreach.php
> 
> Used as shown in the example, I get this:
> Parse error: syntax error, unexpected T_LIST, expecting '&' or T_STRING or
> T_VARIABLE or '$
> 
> Their example:
> 
> <?php
> $array = [
>     [1, 2],
>     [3, 4],
> ];
> 
> foreach ($array as list($a)) {
>     // Note that there is no $b here.
>     echo "$a\n";
> }
> ?>
> 
> The above example will output:
> 
> 1
> 3

This feature is only available since PHP 5.5.0 (as noted in the manual)
-- which version do you use?

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#12095

Fromrichard <noreply@example.com>
Date2013-12-03 10:16 -0500
Message-ID<1bvc98xjvo359.1qzu7dq2au36r.dlg@40tude.net>
In reply to#12093
On Tue, 3 Dec 2013 10:10:59 -0500, richard wrote:

> foreach ($six0 as list($a,$b)){
>   echo $a"\n";
>   echo $b"\n";
>   
> }
> 
> http://us1.php.net/manual/en/control-structures.foreach.php
> 
> Used as shown in the example, I get this:
> Parse error: syntax error, unexpected T_LIST, expecting '&' or T_STRING or
> T_VARIABLE or '$
> 
> Their example:
> 
> <?php
> $array = [
>     [1, 2],
>     [3, 4],
> ];
> 
> foreach ($array as list($a)) {
>     // Note that there is no $b here.
>     echo "$a\n";
> }
> ?>
> 
> The above example will output:
> 
> 1
> 3

Well phooey.
Looks like hostgator doesn't have php 5.5.
Which I need to use "as list".

[toc] | [prev] | [next] | [standalone]


#12096

FromRichard Yates <richard@yatesguitar.com>
Date2013-12-03 11:30 -0800
Message-ID<h8cs991jviohi5s462tvibjs3etmouf1u1@4ax.com>
In reply to#12093
On Tue, 3 Dec 2013 10:10:59 -0500, richard <noreply@example.com>
wrote:

>foreach ($six0 as list($a,$b)){
>  echo $a"\n";
>  echo $b"\n";
>  
>}
>
>http://us1.php.net/manual/en/control-structures.foreach.php
>
>Used as shown in the example, I get this:
>Parse error: syntax error, unexpected T_LIST, expecting '&' or T_STRING or
>T_VARIABLE or '$
>
>Their example:
>
><?php
>$array = [
>    [1, 2],
>    [3, 4],
>];
>
>foreach ($array as list($a)) {
>    // Note that there is no $b here.
>    echo "$a\n";
>}
>?>
>
>The above example will output:
>
>1
>3

  echo $a"\n"; [needs a dot.]

[toc] | [prev] | [next] | [standalone]


#12097

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-12-03 14:40 -0500
Message-ID<l7lc2q$20p$1@dont-email.me>
In reply to#12096
On 12/3/2013 2:30 PM, Richard Yates wrote:
> On Tue, 3 Dec 2013 10:10:59 -0500, richard <noreply@example.com>
> wrote:
>
>> foreach ($six0 as list($a,$b)){
>>   echo $a"\n";
>>   echo $b"\n";
>>
>> }
>>
>> http://us1.php.net/manual/en/control-structures.foreach.php
>>
>> Used as shown in the example, I get this:
>> Parse error: syntax error, unexpected T_LIST, expecting '&' or T_STRING or
>> T_VARIABLE or '$
>>
>> Their example:
>>
>> <?php
>> $array = [
>>     [1, 2],
>>     [3, 4],
>> ];
>>
>> foreach ($array as list($a)) {
>>     // Note that there is no $b here.
>>     echo "$a\n";
>> }
>> ?>
>>
>> The above example will output:
>>
>> 1
>> 3
>
>    echo $a"\n"; [needs a dot.]
>

Actually, in the case, richard is correct (for this line of code, 
anyway).  Simple variables within double quotes are evaluated.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#12099

FromScott Johnson <noonehome@chalupasworld.com>
Date2013-12-03 13:23 -0800
Message-ID<l7li3p$9b5$1@dont-email.me>
In reply to#12097
On 12/3/2013 11:40 AM, Jerry Stuckle wrote:
> On 12/3/2013 2:30 PM, Richard Yates wrote:
>> On Tue, 3 Dec 2013 10:10:59 -0500, richard <noreply@example.com>
>> wrote:
>>
>>> foreach ($six0 as list($a,$b)){
>>>   echo $a"\n";
>>>   echo $b"\n";
>>>
>>> }
>>>
>>> http://us1.php.net/manual/en/control-structures.foreach.php
>>>
>>> Used as shown in the example, I get this:
>>> Parse error: syntax error, unexpected T_LIST, expecting '&' or
>>> T_STRING or
>>> T_VARIABLE or '$
>>>
>>> Their example:
>>>
>>> <?php
>>> $array = [
>>>     [1, 2],
>>>     [3, 4],
>>> ];
>>>
>>> foreach ($array as list($a)) {
>>>     // Note that there is no $b here.
>>>     echo "$a\n";
>>> }
>>> ?>
>>>
>>> The above example will output:
>>>
>>> 1
>>> 3
>>
>>    echo $a"\n"; [needs a dot.]
>>
>
> Actually, in the case, richard is correct (for this line of code,
> anyway).  Simple variables within double quotes are evaluated.
>

However as typical for richard he mistyped his code compared to the sample.

Sample:  "$a\n"
Richards: $a"\n"

Scotty

[toc] | [prev] | [next] | [standalone]


#12113

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-12-03 20:30 -0500
Message-ID<l7m0jo$q9t$2@dont-email.me>
In reply to#12099
On 12/3/2013 4:23 PM, Scott Johnson wrote:
> On 12/3/2013 11:40 AM, Jerry Stuckle wrote:
>> On 12/3/2013 2:30 PM, Richard Yates wrote:
>>> On Tue, 3 Dec 2013 10:10:59 -0500, richard <noreply@example.com>
>>> wrote:
>>>
>>>> foreach ($six0 as list($a,$b)){
>>>>   echo $a"\n";
>>>>   echo $b"\n";
>>>>
>>>> }
>>>>
>>>> http://us1.php.net/manual/en/control-structures.foreach.php
>>>>
>>>> Used as shown in the example, I get this:
>>>> Parse error: syntax error, unexpected T_LIST, expecting '&' or
>>>> T_STRING or
>>>> T_VARIABLE or '$
>>>>
>>>> Their example:
>>>>
>>>> <?php
>>>> $array = [
>>>>     [1, 2],
>>>>     [3, 4],
>>>> ];
>>>>
>>>> foreach ($array as list($a)) {
>>>>     // Note that there is no $b here.
>>>>     echo "$a\n";
>>>> }
>>>> ?>
>>>>
>>>> The above example will output:
>>>>
>>>> 1
>>>> 3
>>>
>>>    echo $a"\n"; [needs a dot.]
>>>
>>
>> Actually, in the case, richard is correct (for this line of code,
>> anyway).  Simple variables within double quotes are evaluated.
>>
>
> However as typical for richard he mistyped his code compared to the sample.
>
> Sample:  "$a\n"
> Richards: $a"\n"
>
> Scotty

Ah, you're right, Scotty.  I was looking at the last part of his code, 
figuring it was similar to the first part.  With Richard, I should have 
known better.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#12110

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2013-12-04 00:48 +0000
Message-ID<XnsA28BC9816557Adougmilmaccom@78.46.70.116>
In reply to#12093
richard <noreply@example.com> wrote in news:1lb2ueqjc0qju.xhszpol7p3t4.dlg@
40tude.net:

> foreach ($six0 as list($a,$b)){
>   echo $a"\n";
>   echo $b"\n";
>   
> }
> 
> http://us1.php.net/manual/en/control-structures.foreach.php
> 
> Used as shown in the example, I get this:
> Parse error: syntax error, unexpected T_LIST, expecting '&' or T_STRING or
> T_VARIABLE or '$

No, you don't. If you get that, then you didn't use it as shown in the example.
> 
> Their example:
> 
> <?php
> $array = [
>     [1, 2],
>     [3, 4],
>];
> 
> foreach ($array as list($a)) {
>     // Note that there is no $b here.

Which means that you didn't use it as shown in the example.

>     echo "$a\n";
> }
> ?>
> 
> The above example will output:
> 
> 1
> 3
> 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web