Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Join Date
    May 2005
    Location
    united kingdom
    Posts
    8,084
    Tokens
    595

    Latest Awards:

    Default pretty please (A) +REP

    Hey guys,


    This will be my third try at learning PHP.

    This page stumps me a bit:
    http://w3schools.com/php/php_arrays.asp

    Could you please explain it in terms that are understandable? :S

    Thanks

    drink up this bottle of yeah
    and P A I N T your body on me


  2. #2
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    $names = array("Peter","Quagmire","Joe"); 
    This sorts Peter, Quagmire and Joe into variable/arrays.

    so $names[0] has the value of "Peter"
    then.. $names[1] has the value of "Quagmire"
    then.. $names[2] has the value of "Joe"

  3. #3
    Join Date
    May 2005
    Location
    united kingdom
    Posts
    8,084
    Tokens
    595

    Latest Awards:

    Default

    Ah, ok, wut about assertive or w.e?

    Also, this http://w3schools.com/php/php_looping.asp confuses me a tiny bit, don't they do the same??

    drink up this bottle of yeah
    and P A I N T your body on me


  4. #4
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by SyrupyMonkey View Post
    Ah, ok, wut about assertive or w.e?

    Also, this http://w3schools.com/php/php_looping.asp confuses me a tiny bit, don't they do the same??
    Looping is "while()" so you'd use that to loop code, such as getting things from a database.

    PHP Code:
    // other page code, including connecting to your database.
    $query mysql_query("SELECT * FROM `table`");

    while(
    $row mysql_fetch_array($query)) { 
    echo 
    "This "$row["name"] ." That.. ";

    So "name" is a row within your database, and using while will list every row in the table.

  5. #5
    Join Date
    May 2005
    Location
    united kingdom
    Posts
    8,084
    Tokens
    595

    Latest Awards:

    Default

    Ok, that sorta confused me :S

    This is going to be a long time...

    drink up this bottle of yeah
    and P A I N T your body on me


  6. #6
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    while() loops code, but you don't really need to loop code often.

  7. #7
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by SyrupyMonkey View Post
    Ok, that sorta confused me :S

    This is going to be a long time...
    An eaysier to understand exapmle

    PHP Code:
    while ( $value 10 ) {
          echo 
    $value//echos numbers
          
    $value++; //adds 1 to the number

    That would display

    123456789
    Lets set the stage on fire, and hollywood will be jealous.

  8. #8
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Quote Originally Posted by SyrupyMonkey View Post
    Ok, that sorta confused me :S

    This is going to be a long time...
    Arrays, sexual - I'll explain them how I get them

    Think of an array as a single table of data, say a few names like the first post was

    Peter
    Quagmire
    Joe

    Put them into a array, separated by commas
    PHP Code:
    $names = array( 'Peter''Quagmire''Joe' ); 
    By default, unless set, to access 'Peter' would be accessible via
    PHP Code:
    $names]; 
    Or instead of that, you could set them yourself

    PHP Code:
    $names514 ] = 'Peter';
    $names415 ] = 'Quagmire';
    $names666 ] = 'Joe'
    You could access 'Peter' via
    PHP Code:
    $names514 ]; 
    You don't have to use numbers as ID keys, for example, you could have the name 'Peter' as a key and have a value behind it

    EG:

    PHP Code:
    $names = array( 'Peter' => 'Fat' ); 
    or

    PHP Code:
    $names'Peter' ] = 'Fat'
    Multidimensional Arrays are fun too

    Say, you have different surnames, and behind each surname you got people
    PHP Code:
    $surnames = array( 
    'Smith' => array( 'Mark''John''Sally' ),
    'Barker' => array( 'Joe''Dylan''Josh' )
    ); 
    Look, you have two surnames in the array 'Smith' and 'Barker', behind each are the names of the people with that surname.

    Lets access 'Smith'

    PHP Code:
    $surnames'Smith' ][ ]; 
    Now, that will return 'Mark', for John
    PHP Code:
    $surnames'Smith' ][ ]; 
    Same with 'Barker'

    PHP Code:
    $surnames'Barker' ][ ]; 
    Will return 'Josh'

    Now, you wanted to see how the foreach worked, for example

    Just read it as I put it
    PHP Code:
    $array = array( 'Kill''People''Who''Do''Not''Understand''This' );
    foreach( 
    $array as $value )
    {
     echo( 
    $value '<br />' );

    Say, for each $value in $array

    So its going to get each value from $array and echo it

    the result will be
    Kill
    People
    Who
    Do
    Not
    Understand
    This
    Last edited by Protege; 23-08-2008 at 09:49 PM.
    Hi, names James. I am a web developer.

  9. #9
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Protege View Post
    Arrays, sexual - I'll explain them how I get them

    Think of an array as a single table of data, say a few names like the first post was

    Peter
    Quagmire
    Joe

    Put them into a array, separated by commas
    PHP Code:
    $names = array( 'Peter''Quagmire''Joe' ); 
    By default, unless set, to access 'Peter' would be accessible via
    PHP Code:
    $names]; 
    Or instead of that, you could set them yourself

    PHP Code:
    $names514 ] = 'Peter';
    $names415 ] = 'Quagmire';
    $names666 ] = 'Joe'
    You could access 'Peter' via
    PHP Code:
    $names514 ]; 
    You don't have to use numbers as ID keys, for example, you could have the name 'Peter' as a key and have a value behind it

    EG:

    PHP Code:
    $names = array( 'Peter' => 'Fat' ); 
    or

    PHP Code:
    $names'Peter' ] = 'Fat'
    Multidimensional Arrays are fun too

    Say, you have different surnames, and behind each surname you got people
    PHP Code:
    $surnames = array( 
    'Smith' => array( 'Mark''John''Sally' ),
    'Barker' => array( 'Joe''Dylan''Josh' )
    ); 
    Look, you have two surnames in the array 'Smith' and 'Barker', behind each are the names of the people with that surname.

    Lets access 'Smith'

    PHP Code:
    $surnames'Smith' ][ ]; 
    Now, that will return 'Mark', for John
    PHP Code:
    $surnames'Smith' ][ ]; 
    Same with 'Barker'

    PHP Code:
    $surnames'Barker' ][ ]; 
    Will return 'Josh'

    Now, you wanted to see how the foreach worked, for example

    Just read it as I put it
    PHP Code:
    $array = array( 'Kill''People''Who''Do''Not''Understand''This' );
    foreach( 
    $array as $value )
    {
     echo( 
    $value '<br />' );

    Say, for each $value in $array

    So its going to get each value from $array and echo it

    the result will be
    Post stuck (Forum Moderator) - keep up the unsexual work

  10. #10
    Join Date
    May 2008
    Posts
    605
    Tokens
    0

    Default

    Arrays are handy but you don't always need them.
    You could use something as simple as:

    PHP Code:
    $name1 "Bob";
    $name2 "Marley";
    echo (
    ' $name1 '); 
    But stick to arrays as it will be the most professional way of doing things.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •