Jump to content

Can someone explain this please ?


Rommeo

Recommended Posts

hi

 

i downloaded php-photo script. And want to change some codes in it. But there are many things that i could not understand.

 

1 )

The language file is like this

<?
$pa_texts=Array(
"ID_NEXT" => "next",
.
.
.
);
?>

Is this an array?

Why he's using an array here ? Don't we use $array[1]; etc. to call an array ?

 

2-) Another interesting thing that i have never seen.

he is calling these IDs like this line

...<h6><?p("ID_SETUP_MENU_ECARD");?></h6>...

As I know I cant start a code like "<?p ". I should use space like "<? p" at least dreamweaver does not accept when I use it like he's using. How can he use it ?

 

3-) What is  "<?p("ID_SETUP_MENU_ECARD");?>" this for ?? I could not find a "function p" though.

 

4-) As I'm new about php programming, I also could not understand the differerence between $ID="hello", and $ID='hello'; and "ID" => "hello";

 

I ll be glad if someone can explain at least any of these.

 

Thanx in advance.

Link to comment
https://forums.phpfreaks.com/topic/119763-can-someone-explain-this-please/
Share on other sites

1) $var = array(red, blue, green);

that assigns:

$var[0] to red

$var[1] to blue

$var[2] to green

 

You can do it more then one way yer, but this is my preffered way.

 

3)

<?p("ID_SETUP_MENU_ECARD");?>

I dunno about the ID_SETUP_MENU_ECARD, as ive had no need for this method - but the <?p is not a function it's just the start of the php tag <?php is preffer (again by me).

 

4)

$ID = "hello" and $ID = 'hello' are basically the same, however with "hello" you need to add escape characters for newlines etc, with '' it prints EVERYTHING rather then starting a new line.

"ID" => "hello" assigns array keys =]

 

Im sure thats right as i'm a learner too :P

also look up variable interpolation.  let's say i do:

 

$foo = 'bar';
echo "this is $foo <br />";
echo 'this is $foo';

 

this will output:

 

this is bar
this is $foo

 

using double quotes, PHP interpolates the variables.  that is, it searches the string for variables (such as $foo) and replaces them with their values.  single quotes are interpreted literally.  the latter is often considered faster for processing since PHP doesn't have to scour the string.

 

i believe there are settings where you can enable short tags (which is what allows one to use <? and >), and there may also be a setting that allows you to just open, write a variable, and close and PHP will echo the variable for you.  i've seen it as:

 

<?=$array['key']?>

 

(note the equal sign) but i've never seen it as you've written it.

<?p("ID_SETUP_MENU_ECARD");?>

 

 

Not sure about the <?p part of it as it should be <?php  or <?= as folks have mentioned,

 

if p is indeed a function, it is a user defined function. e.g.

 

<?php

function p($someVar)
{
    if(isset($someVar))
    {
          return $someVar;
    }
}


echo p('Hello World');

?>

 

This would print on-screen; Hello World

 

ID_SETUP_MENU_ECARD may be a constant. We can set variables, where a value may change, we can also set a constant where the value is always the same....

 

<?php
define(MY_CONSTANT,'I am the value of this constant');


echo MY_CONSTANT;
?>

will print on-screen; I am the value of this constant

 

<?
$pa_texts=Array("ID_NEXT" => "next",...);
?>

 

This does not look right, it produces a syntax error.

 

It is using short open tags, which is not real recommended as moving the code to a server that don't support it, will make your life more difficult. Always try to use <?php for every opening php tag. A few extra keystrokes there can save lots of work later.

 

But is what that is doing is creating the array. You are correct that you can access array items with the method you presented, but this line is to create the array.

 

Hope this helps ya.

 

Nate

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.