FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


-> and =>





ThomasDesigns
So, I have not used PHP for anything you would call 'advanced'. All of my code to date has been pretty basic.

I have been trying to make applications of my own to better learn more advanced things, but it all seems so confusing.

I was bored just now and was looking through the source code of PHPBB 3. Don't worry, I didn't expect to learn anything from just looking. But a couple things did catch my eye.

I was looking at the code and saw a lot of things like this:
Code:
if (!$db->sql_affectedrows())
         {
            $db->sql_return_on_error(true);

            $sql_ary = array(
               'user_id'      => (int) $user->data['user_id'],
               'topic_id'      => (int) $topic_id,
               'forum_id'      => (int) $forum_id,
               'mark_time'      => ($post_time) ? (int) $post_time : time(),
            );

            $db->sql_query('INSERT INTO ' . TOPICS_TRACK_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));

            $db->sql_return_on_error(false);
         }


In this little snippet, I see a lot I don't understand. I can grasp the gist of it, storing an array in a database, but much of it confuses me.

I see a lot of symbols, or maybe you would call them operators, in there such as '->' '=>' and 'X ? Y : Z'.

I know that => has something to do with multidimensional arrays, but that is the extent of my understanding.

Perhaps someone could point me in the right direction to some tutorials to help me grasp these concepts. I have been through the PHP tuts on W3Schools and can't find much there about this criteria.
mathiaus
X ? Y : Z
is an IF (IF X THEN Y ELSE Z)
eg
Code:
$test = isset($example) ? $example : $default_example;

rather than
Code:
if(isset($example)) {
   $test = $example;
} else {
   $test = $default_example;
}

The IF clause can be more complicated but these are great for short things where a value should either be one value or another.


The -> are used in objects. Hard to explain though so I'll forward you to http://uk.php.net/manual/en/language.oop5.basic.php

=> is used so assign a value to a key in an array
KEY => VALUE
Another forward -> http://uk.php.net/manual/en/language.types.array.php
ThomasDesigns
Thanks a bunch!
phpc0d3r
Alright Just For Clarity For Other Users

=> is used for arrays

ex:
Code:

$array = array("this is a key" => "this is a value");  //  => establishes a relationship between the key and the value.

foreach($array as $key => $value){ 
echo $key.$value;
}


-> is used for objects (OOP)
Code:

$myClass = new MyClass;

$myClass->myfunction();  //MyFunction is contained within MyClass

echo $myClass->myVariable; //MyVariable is a variable within MyClass


I hope this clarified this subject for a few people. At least I hope it didn't confuse you more. This is a very good topic, because a lot of programmers get confused about the difference between => and ->.
Related topics
Styling <abbr> in IE
<hr> stilosi con i CSS
Scripts > Advance Clock
WinXP: Speed up your Start->All Programs
::> CyberCulture
Window$ XP HIDDEN APPS>>>
Java -> how to get the NIC's MAC Address?
Some sketches I made ><v
Adding <br /> to text area
Is it possible to change the bgcolor of <iframe> in IE
What for <script type="text/php"> is used?
TUTORIAL => Compress your BSP Files with BZIP2
7800 Gt
Urgent Help > Serious Virus Infection
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.