Tagged: Software RSS Toggle Comment Threads | Keyboard Shortcuts

  • softwareandme 9:24 pm on April 21, 2010 Permalink
    Tags: , php syntax, Software, software development   

    Php Syntax And Variables (2) 

    Hi,

    We are going to learn php syntax and variables on this article.

    We have talked about php syntax on the first php article, the syntax looks like c,c++,java and if you know one of these languages’ syntax it will be easy to learn php syntax.

    Php is a scripting language and we must say to its interpreter where the php code begins and where it ends. We use to tell the php interpreter it is a php script and it should interprets the script among these tags.

    <?php
    // What are these slashes?
    //Php script ends here
    ?>
    

    //: Double slashes means this line will not be interpreted by the interpreter, this line wont run , it is used for comment lines. Comment lines may be used to add extra information about the code, adding todo item, informing your colleagues about the code, etc.

    Before starting php syntax again we should look at what are variables and how can we define them. Variable stores data in it, variable name is a symbolic name associated with a value. Php has different variable types but php dont use them to define variables’ types. Php knows type of variable according to its value.If you assign a string to a variable then you may assign an integer and again you may assign an object to the variable.

    If you try to do this on C++ you have to use type casting. Php is a loosely typed language because of this feature.

    <?
    $string = 'Hello world!'; //String variable
    $string = 7; //Integer
    $string = 7.3; //Floating number , Float
    $string = new Object(); // Object
    ?>
    

    Php variables have $ sign in front of them. The second character of the variable i mean the character after $ sign must be a letter or underscore. Variable stores data so we should know how to assign data to a variable, we assign data to a variable by = (equals) sign. Equals assigns from right to the left, what does it mean? It means = (equals) gets the value from its right and puts it into its left. Php uses ; sign to assign values,references to variables, run functions.

    Php uses { } bracets for code blocks, code block is a piece of code which does something (multiply two numbers, checking if user has logged in etc), we write code inside { and } tags in code blocks. Code blocks are used in comparisons, functions, class methods, class declarations.

    In programming languages there are operators for making some processes on variables,functions,objects, like multiplying two numbers, assigning an object as a reference, comparing two strings etc. The next article describes php operators so please try to understand the operators which are located below;

    Arithmetic Operators

    Operator Description Example Result
    + Addition x=2
    x+2
    4
    - Subtraction x=2
    6-x
    4
    * Multiplication x=4
    x*3
    12
    / Division 8/2
    16/4
    4
    4
    % Modulus (division remainder) 7%2
    10%8
    10%2
    1
    2
    0
    ++ Increment x=7
    x++
    x=8
    Decrement x=7
    x–
    x=6

    Assignment Operators

    Operator Example Is The Same As
    = x=y x=y
    += x+=y x=x+y
    -= x-=y x=x-y
    *= x*=y x=x*y
    /= x/=y x=x/y
    .= x.=y x=x.y
    %= x%=y x=x%y

    Comparison Operators

    Operator Description Example
    == is equal to 4==8 returns false
    != is not equal 4!=8 returns true
    <> is not equal 4<>8 returns true
    > is greater than 4>8 returns false
    < is less than 4<8 returns true
    >= is greater than or equal to 4>=8 returns false
    <= is less than or equal to 4<=8 returns true

    Logical Operators

    Operator Description Example
    && and x=6
    y=3

    (x < 10 && y > 1) returns true

    || or x=6
    y=3

    (x==4 || y==4) returns false

    ! not x=6
    y=3

    !(x==y) returns true

    There are also different operators in php we try to explain them in our next article.

     
  • softwareandme 4:06 am on July 31, 2009 Permalink
    Tags: developer, , open source, program, programmer, Software, software engineer   

    Greetings,

    I am a software engineer / programmer who developed programs with java,c++,c# and php with little bash and python, but mostly php and c++. I call my self  “software repairer” because i always had to develop somebody else’s projects and repair them, i am not saying it is a bad. I have also projects more than ten, none of my projects have been finished, they are all ( commercial ones for the companies i work and the free ones have the same end ) un-finished. They are all in beta phases or in 0.0.1.1234 version.

    If you ask me why, i can give a lot of excuses and also detailed information about the excuses but who cares, i have a lot of unfinished work for 4 years. They are all waiting to see the sun light.

    I am an open source and free software enthusiast, i learned a lot from the open source projects, they gave me the chance to know how to develop a software like a real professional. It is important to know how not to write code also, my commercial experiences in some companies taught me how not to write code. I try to obey the golden rules of software engineering, try to follow IEEE standards in all of the life cycle and development phases.

    I am using Slackware and Debian, nowadays i have to use Windows a lot.

    I hope i can write my experiences about software and software development, I also have to say that there are a lot of things i have to learn about software engineering, but sharing knowledge makes it precious. If you dont share your knowledge it is just useful to you, it means that it is not useful in real if you are so selfish.

    I also play bass guitar, i am an amateur bass guitarist. Sometimes i may write something related to music espacially bass guitars, i am not a musician i cant write anything music theory.

    I will try to add my daily experiences as a developer,  they will be mostly about web programming with php, postgresql, apache, mysql, c++, wt.

    Hope you will like my posts.

    Thanks for reading this article.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel
Follow

Get every new post delivered to your Inbox.