FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » foreach as list
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
foreach as list [message #184041] Tue, 03 December 2013 10:10 Go to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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
Re: foreach as list [message #184042 is a reply to message #184041] Tue, 03 December 2013 10:18 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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
Re: foreach as list [message #184043 is a reply to message #184041] Tue, 03 December 2013 10:16 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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".
Re: foreach as list [message #184044 is a reply to message #184041] Tue, 03 December 2013 14:30 Go to previous messageGo to next message
Richard Yates is currently offline  Richard Yates
Messages: 86
Registered: September 2013
Karma: 0
Member
add to buddy list
ignore all messages by this user
On Tue, 3 Dec 2013 10:10:59 -0500, richard <noreply(at)example(dot)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.]
Re: foreach as list [message #184045 is a reply to message #184044] Tue, 03 December 2013 14:40 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 12/3/2013 2:30 PM, Richard Yates wrote:
> On Tue, 3 Dec 2013 10:10:59 -0500, richard <noreply(at)example(dot)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(at)attglobal(dot)net
==================
Re: foreach as list [message #184047 is a reply to message #184045] Tue, 03 December 2013 16:23 Go to previous messageGo to next message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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(at)example(dot)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
Re: foreach as list [message #184058 is a reply to message #184041] Tue, 03 December 2013 19:48 Go to previous messageGo to next message
Doug Miller is currently offline  Doug Miller
Messages: 171
Registered: August 2011
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
richard <noreply(at)example(dot)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
>
Re: foreach as list [message #184061 is a reply to message #184047] Tue, 03 December 2013 20:30 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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(at)example(dot)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(at)attglobal(dot)net
==================
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Re: SEO SERVICES
Next Topic: Can I download file with address like this "http://***.com/file.php/ABC.html" automatically ?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Oct 23 04:10:46 EDT 2017

Total time taken to generate the page: 0.00786 seconds