Connecting Tech Pros Worldwide Help | Site Map

mult variable assignmesnt on one line

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 04:20 AM
Bart Nessux
Guest
 
Posts: n/a
Default mult variable assignmesnt on one line

In Python, I can do something like this:

a,b,c = 1,2,3

How might I do this with PHP?

Thanks,
Bart


  #2  
Old July 17th, 2005, 04:20 AM
Bruno Desthuilliers
Guest
 
Posts: n/a
Default Re: mult variable assignmesnt on one line

Bart Nessux wrote:[color=blue]
> In Python, I can do something like this:
>
> a,b,c = 1,2,3
>
> How might I do this with PHP?
>[/color]
Have a look at list()
http://www.php.net/manual/en/function.list.php

list($a, $b, $c) = Array(1, 2, 3);

should do it. But it's not as readable as Python... !-)

Bruno

  #3  
Old July 17th, 2005, 04:20 AM
Bart Nessux
Guest
 
Posts: n/a
Default Re: mult variable assignmesnt on one line

Bruno Desthuilliers wrote:[color=blue]
> Bart Nessux wrote:
>[color=green]
>> In Python, I can do something like this:
>>
>> a,b,c = 1,2,3
>>
>> How might I do this with PHP?
>>[/color]
> Have a look at list()
> http://www.php.net/manual/en/function.list.php
>
> list($a, $b, $c) = Array(1, 2, 3);
>
> should do it. But it's not as readable as Python... !-)
>
> Bruno
>[/color]

Thanks for the tip... guess I'll stick to doing on var at a time. One
last question: How can I split long lines of PHP code up into smaller
lines? For example, how can I turn this line:

$12 = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;

into this line:

$12 = xxxxxxxxxxxxxx
xxxxxxxxxxxxxx
xxxxxxxxxxxxxx;

Thanks,
Bart

  #4  
Old July 17th, 2005, 04:20 AM
Bruno Desthuilliers
Guest
 
Posts: n/a
Default Re: mult variable assignmesnt on one line

Bart Nessux wrote:[color=blue]
> Bruno Desthuilliers wrote:
>[color=green]
>> Bart Nessux wrote:
>>[color=darkred]
>>> In Python, I can do something like this:
>>>
>>> a,b,c = 1,2,3
>>>
>>> How might I do this with PHP?
>>>[/color]
>> Have a look at list()
>> http://www.php.net/manual/en/function.list.php
>>
>> list($a, $b, $c) = Array(1, 2, 3);
>>
>> should do it. But it's not as readable as Python... !-)
>>
>> Bruno
>>[/color]
>
> Thanks for the tip... guess I'll stick to doing on var at a time.[/color]

Yeps, I think that's a better choice here. Still, the list() function
may come in handy sometimes...
[color=blue]
> One
> last question: How can I split long lines of PHP code up into smaller
> lines? For example, how can I turn this line:
>
> $12 = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
>
> into this line:
>
> $12 = xxxxxxxxxxxxxx
> xxxxxxxxxxxxxx
> xxxxxxxxxxxxxx;
>[/color]
Assuming the xxxx is php code (not a string), you don't have anything
special to do. Like C and most maintstream languages, PHP uses ';' as
the instruction delimiter. So newlines, whitespaces etc have no special
meaning.

HTH
Bruno

  #5  
Old July 17th, 2005, 04:21 AM
Garp
Guest
 
Posts: n/a
Default Re: mult variable assignmesnt on one line


"Bruno Desthuilliers" <bdesth.quelquechose@free.quelquepart.fr> wrote in
message news:405e0f64$0$291$636a15ce@news.free.fr...
<snip>[color=blue][color=green]
> > One
> > last question: How can I split long lines of PHP code up into smaller
> > lines? For example, how can I turn this line:
> >
> > $12 = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
> >
> > into this line:
> >
> > $12 = xxxxxxxxxxxxxx
> > xxxxxxxxxxxxxx
> > xxxxxxxxxxxxxx;
> >[/color]
> Assuming the xxxx is php code (not a string), you don't have anything
> special to do. Like C and most maintstream languages, PHP uses ';' as
> the instruction delimiter. So newlines, whitespaces etc have no special
> meaning.
>
> HTH
> Bruno[/color]

In the case that it IS a string, you could do this (using the .
concatenation operator):
$a = "xxxxxxxxxxxxxx".
"xxxxxxxxxxxxxx".
"xxxxxxxxxxxxxx";

Garp


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.