Connecting Tech Pros Worldwide Help | Site Map

mult variable assignmesnt on one line

Bart Nessux
Guest
 
Posts: n/a
#1: Jul 17 '05
In Python, I can do something like this:

a,b,c = 1,2,3

How might I do this with PHP?

Thanks,
Bart

Bruno Desthuilliers
Guest
 
Posts: n/a
#2: Jul 17 '05

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

Bart Nessux
Guest
 
Posts: n/a
#3: Jul 17 '05

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

Bruno Desthuilliers
Guest
 
Posts: n/a
#4: Jul 17 '05

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

Garp
Guest
 
Posts: n/a
#5: Jul 17 '05

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


Closed Thread