Re: Pre/Post inc (Was array conversion)

[email protected] (Nathan Rixham)
Newsgroups php.general
Message-ID <[email protected]>
Richard Quadling wrote:
> On 20 February 2010 11:18,  <[email protected]> wrote:
>> Or:
>>
>> $a = array ('Cats', 'white', 'Dogs', 'black', 'Mice', 'grey', 'Camels', 'brown');
>> $b = '';                                // Just in case it has some leftover value
>> $k = 2* (int) (count ($a)/2);   // ensure even no of terms
>> $i = 0; while ($i < $k)
>>        {
>>        $b[$a[$i++]] = $a[$i++];  // ***
>>        }
>>
>> And this works:
>> $i = 0; $k = array_keys($b);
>> while ($i < count($b)) {        echo '<h5>'.$i.': '.$k[$i].' = '. $b[$k[$i++]].'</h5>'; }
>>
>> 0: Cats = white
>> 1: Dogs = black
>> 2: Mice = grey
>> 3: Camels = brown
>>
>> ( *** I have always been wary of using statements like this because I was unsure when the
>> incrementing would occur, so I tried it.)
>>
>> Clancy
> 
> 
> <?php
> $i = 10;
> echo $i++; // Shows 10 and $i becomes 11
> echo ++$i; // $i becomes 12 and 12 is shown.
> ?>
> 
> Post increment and pre increment.
> 
> No need to be "wary" of them.
> 
> http://docs.php.net/manual/en/language.operators.increment.php
> 

Expanding on what Richard says; there does seem to be a growing number
of people who haven't stopped to learn the very basics of PHP (or
languages in general).

I'd strongly recommend that all those in doubt over the basics take a
few hours out to (re-)familiarise themselves; and there's no finer
resource to do this than the php manual [1]

You'll notice the manual goes as follows:
# Basic syntax
# Types
# Variables
# Constants
# Expressions
# Operators
# Control Structures
# Functions
... more

And that's the order in which you should learn; in short you can't
really program or script without knowing basics through control structures.

Do hope this mail doesn't sound condescending in any way; as it's meant
with the best intentions and really will make you're (working) life a
lot easier. I myself still refer back to these base sections
periodically, and every time I do - a new detail pops out that makes
something easier.

[1] http://docs.php.net/manual/en/langref.php

Many Regards,

Nathan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.